Part Number Hot Search : 
MC8T97P EC842 STIL08T5 005036 GRM31C ODUCT M74HC7 PC150
Product Description
Full Text Search
 

To Download XMEGAD Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  this document contains complete and detai led description of all modules included in the avr? xmega tm d microcontroller family. the xm ega d is a family of low power, high performance and peripheral rich cmos 8/16-bit microcontrollers based on the avr enhanced risc architecture. the available xmega d modules described in this manual are: ? avr cpu ? memories ? event system ? system clock and clock options ? power management and sleep modes ? system control and reset ? wdt - watchdog timer ? interrupts and programmable multi-level interrupt controller ? port - i/o ports ? tc - 16-bit timer/counter ? awex - advanced waveform extension ? hi-res - high reso lution extension ? rtc - real time counter ? twi - two wire serial interface ? spi - serial peri pheral interface ? usart - universal synchronous and asynchro nous serial receiver and transmitter ? ircom - ir comm unication module ? adc - analog to digital converter ? ac - analog comparator ? pdi - program and debug interface ? memory programming ? peripheral address map register summary ? interrupt vector summary ? instruction set summary 8210b- avr-04/10 8-bit xmega d microcontroller xmega d manual preliminary
2 8210b?avr?04/10 xmega d 1. about the manual this document contains in-depth documentation of all peripherals and modules available for the avr xmega d microcontroller family. all features are documented on a functional level and described in a general sense. all peripherals a nd modules described in this manual may not be present in all xmega d devices. for all device specific information such as characterization data, memory sizes, modules and peripherals available and their absolute memory addresses refer to the device datasheets. when several instances of one peripheral such as a port exist in one device, each instance of a module will have a unique name, such as porta, portb etc. register, bit names are unique within one module. for more details on applied use and code examples for all peripherals and modules, refer to the xmega specific application notes available from: http://www.atmel.com/avr. 1.1 reading the manual the main sections describe the various modules and peripherals. each section contains a short feature list of the most important features and a short overview describing the module. the remaining section describes the features and functions in more details. the register description sections list all registers, and describe each bit/flag and its function. this includes details on how to set up and enable vari ous features in the module. when multiple bits are needed for a configuration setting, these are grouped together in a bit group. the possible bit group configurations are listed for all bit groups together with their associated group configu- ration and a short description. the group configuration refer to the defined configuration name used in the xmega and assembler header files and application note source code. the register summary sections list the internal register map for each module type. the interrupt vector summary sections list the interrupt vectors and offset address for each mod- ule type. 1.2 resources a comprehensive set of development tools, app lication notes and datasheets are available for download on http:// www.atmel.com/avr. 1.3 recommended reading ? xmega d device datasheets ? xmega application notes this manual only contains general modules and peripheral descriptions. the xmega d device datasheet contains device specific information. the xmega application notes contain example code and show applied use of the modules and peripherals. for new users it is recommended to read the avr1000 - getting started writing c-code for xmega, and avr1900 - getting started with atxmega128a1 application notes.
3 8210b?avr?04/10 xmega d 2. overview the xmega d is a family of low power, high performance and peripheral rich cmos 8/16-bit microcontrollers based on the avr enhanced risc architecture. by executing powerful instruc- tions in a single clock cycle, the xmega d achieves throughputs approaching 1 million instructions per second (mips) per mhz allowing the system desi gner to optimi ze power con- sumption versus processing speed. the avr cpu combines a rich instruction set with 32 general purpose working registers. all the 32 registers are directly connected to the arithmetic logic unit (alu), allowing two independent registers to be accessed in one single instructi on, executed in one clock cycle. the resulting architecture is more code efficient while achi eving throughputs many times faster than conven- tional single-accumula tor or cisc based microcontrollers. the xmega d devices provide the following features: in-system programmable flash with read-while-write capabilities, internal eepr om and sram, four-cha nnel event system and programmable multi-level interrupt controller, up to 78 general purpose i/o lines, 16-bit real time counter (rtc), up to five flexible 16-bit timer/counters with compare modes and pwm, up to four usarts, one i 2 c and smbus compatible two wire serial interface (twi), up to two serial peripheral interfaces (spis), 16-channel, 12-bit adc, with optional differential input and programmable gain, two analog comparator s with window mode, programmable watchdog timer with separate internal osc illator, accurate inte rnal oscillators with pll and prescaler, and programmable brown-out detection. the program and debug interface (pdi), a fast 2-pin interface for programming and debugging, is available. the xmega d devices have five software selectable power saving modes. the idle mode stops the cpu while allowing the sram, event system, interrupt controller and all peripherals to con- tinue functioning. the power-down mode saves the sram and register contents but stops the oscillators, disabling all other functions until the next twi- or pin-change interrupt, or reset. in power-save mode, the asynchronous real time counter continues to run, allowing the applica- tion to maintain a timer base while the rest of the device is sleeping. in standby mode, the crystal/resonator oscillator is kept running whil e the rest of the device is sleeping. this allows very fast start-up from external crystal combined with low power consumption. in extended standby mode, both the main os cillator and the asynch ronous timer continue to run. to further reduce power consumption, the peripheral clock to each individual peripheral can optionally be stopped in active mode and idle sleep mode. the devices are manufactured using atmel's high-density nonvolatile memory technology. the program flash memory can be reprogrammed in-system through the pdi. a bootloader running in the device can use any interface to download the application program to the flash memory. the bootloader software in the boot flash secti on will continue to run while the application flash section is updated, providing true read-while-write operation. by combining an 8/16-bit risc cpu with in-system self-programmable flas h, the atmel xmega d is a powerful micro- controller family that provides a highly flexible and cost effective solution for many embedded applications. the xmega d devices are supported with a full suite of program and system development tools including: c compilers, macro assemblers, program debugger/simulators, programmers, and evaluation kits.
4 8210b?avr?04/10 xmega d 2.1 block diagram figure 2-1. xmega d block diagram power supervision por/bod & reset port a (8) port b (8) event routing network bus controller sram adca aca ocd port k (8) port j (8) port h (8) pdi cpu ph[0..7] pj[0..7] pk[0..7] pa[0..7] pb[0..7] watchdog timer watchdog oscillator interrupt controller data bus data bus prog/debug controller vcc gnd port r (2) xtal1 xtal2 pr[0..1] tosc1 tosc2 pq[0..3] oscillator circuits/ clock generation oscillator control real time counter event system controller pdi_data reset/ pdi_clk sleep controller flash eeprom nvm controller ircom port q (4) port c (8) pc[0..7] tcc0:1 usartc0 twic spic pd[0..7] pe[0..7] pf[0..7] port d (8) tcd0 usartd0 spid tcf0 usartf0 tce0 usarte0 port e (8) port f (8) event routing network int. refs. arefa arefb tempref vcc/10
5 8210b?avr?04/10 xmega d 3. avr cpu 3.1 features ? 8/16-bit high perfor mance avr risc cpu ? 138 instructions ? hardware multiplier ? 32x8-bit registers directly connected to the alu ? stack in ram ? stack pointer accessible in i/o memory space ? direct addressing of up to 16m bytes of program memory and 16m bytes of data memory ? true 16/24-bit access to 16/24-bit i/o registers ? efficient support for both 8-, 16- and 32-bit arithmetic ? configuration change protection of system critical features 3.2 overview xmega uses the 8/16-bit avr cpu. the main function of the cpu is to ensure correct program execution. the cpu is able to access memories, perform calculations and control peripherals. interrupt handling is described in a separate section, refer to ?interrupts and programmable multi-level inte rrupt controller? on page 95 for more details on this. 3.3 architectural overview in order to maximize performance and parallelism, the avr uses a harvard architecture with separate memories and buses for program and data. instructions in the program memory are executed with a single level pipelining. while one instruction is being executed, the next instruc- tion is pre-fetched from the program memory. this concept enables instructions to be executed in every clock cycle. for the summar y of all avr instructions refer to ?instruction set summary? on page 296 . for details of all avr instructions refer to http://www.atmel.com/avr.
6 8210b?avr?04/10 xmega d figure 3-1. block diagram of the avr architecture the arithmetic logic unit (alu) supports arit hmetic and logic operations between registers or between a constant and a register. single register operations can also be executed in the alu. after an arithmetic operation, the status register is updated to reflect information about the result of the operation. the alu is directly connected to the fast-access register file. the 32 x 8-bit general purpose working registers all have single clock cycle access time allowing single-cycle arithmetic logic unit (alu) operation between registers or between a register and an immediate. six of the 32 registers can be used as three 16-bit address po inters for program and data space addressing - enabling efficient address calculations. the memory spaces are all linear and regular memory maps. the data memory space and the program memory space are two different memory spaces. the data memory space is divi ded into i/o registers and sr am. in addition the eeprom can be memory mapped in the data memory. all i/o status and control registers reside in the lowest 4k bytes addresses of the data memory. this is referred to as the i/o memory space. th e lowest 64 addresses ca n be accessed directly, or as the data space locations from 0x00 - 0x 3f. the rest is the extended i/o memory space, ranging from 0x40 to 0x1fff. i/o registers here must be access as data space locations using load (ld/lds/ldd) and store (st/sts/std) instructions. the sram holds data, and code cannot be exec uted from here. it can easily be accessed through the five different addressing modes s upported in the avr architecture. the first sram address is 0x2000. data address 0x1000 to 0x1fff is reserved for me mory mapping of eeprom. flash program memory instruction decode program counter ocd 32 x 8 general purpose registers alu multiplier instruction register status/ control peripheral module 1 peripheral module n eeprom pmic sram data bus data bus
7 8210b?avr?04/10 xmega d the program memory is divided in two sections , the application program section and the boot program section. both sections have dedicated lock bits for write and read/write protection. the spm instruction that is used for self-programming of the application flash memory must reside in the boot program section. a third section exists inside the application section. this section, the application table section, has separate lock bits for write and read/write protection. the application table section can be used for storing non-volatile data or application software. 3.4 alu - arithmetic logic unit the arithmetic logic unit (alu) supports arit hmetic and logic operations between registers or between a constant and a register. single regist er operations can also be executed. the alu operates in direct connection with all the 32 general purpose registers. in a typical single cycle alu operation, two operands are output from the register file, the operation is executed, and the result is stored back in the register file. in order to operate on data in the data memory, these must first be loaded into the register file. after the operation, the data can be stored from the register file and back to the data memory. the alu operations are divided into three main categories - arithmetic, logical, and bit-functions. after an arithmetic or logic operation, the status register is updated to reflect information about the result of the operation. 3.4.1 hardware multiplier the multiplier is capable of multiplying two 8-bit numbers into a 16-bit result. the hardware mul- tiplier supports different variations of signed and unsigned integer and fractional numbers: ? multiplication of unsigned integers. ? multiplication of signed integers. ? multiplication of a signed integer with an unsigned integer. ? multiplication of unsigned fractional numbers. ? multiplication of signed fractional numbers. ? multiplication of a signed fractional number and with an unsigned. a multiplication takes two cpu clock cycles. 3.5 program flow after reset, the program will start to execute from prog ram address 0. progra m flow is provided by conditional and unconditional jump and call instru ctions, able to directly address the whole address space. most instructions have a single 16-bit word format. every program memory address contains a 16- or 32-bit instruction. the program counter (pc) addresses the location from where instructions are fetched. during inte rrupts and subroutine calls, the return address pc is stored on the stack. when an enabled interrupt occurs, the program counter is vectored to the actual interrupt vector in order to execute the interrupt handling routine. hardware clears the corresponding interrupt flag automatically.
8 8210b?avr?04/10 xmega d a flexible interrupt controller has dedicated control registers with an additional global interrupt enable bit in the status register. all interrupts have a separate interrupt vector, starting from the reset vector at address 0 in the program memory. all interrupts have a programmable interrupt level. within each level they ha ve priority in accordance with their interrupt vector position where the lower interrupt vector address has the higher priority. 3.6 instruction execution timing the avr cpu is driven by the cpu clock clk cpu . no internal clock division is used. figure 3-2 on page 8 shows the parallel instruction fetches and instruction executions enabled by the har- vard architecture and the fast-access register file concept. this is the basic pipelining concept to obtain up to 1 mips per mhz with the corr esponding unique results for functions per cost, functions per clocks, and functions per power-unit. figure 3-2. the parallel instruction fetches and instruction executions figure 3-3 on page 8 shows the internal timing concept for the register file. in a single clock cycle an alu operation using two register operands is executed, and the result is stored back to the destination register. figure 3-3. single cycle alu operation clk 1st instruction fetch 1st instruction execute 2nd instruction fetch 2nd instruction execute 3rd instruction fetch 3rd instruction execute 4th instruction fetch t1 t2 t3 t4 cpu total execution time register operands fetch alu operation execute result write back t1 t2 t3 t4 clk cpu
9 8210b?avr?04/10 xmega d 3.7 status register the status register (sreg) contains information about the result of the most recently executed arithmetic or logic instruction. this information can be used for altering program flow in order to perform conditional operations. note that the st atus register is updated after all alu opera- tions, as specified in the instruction set referenc e. this will in many cases remove the need for using the dedicated compare instructions, resulting in faster and more compact code. the status register is not automatically stored when entering an interrupt routine nor restored when returning from an interrupt. this must be handled by software. the status register is accessible in the i/o memory space. 3.8 stack and stack pointer the stack is used for storing return addresses after interrupts and subroutine calls. it can also be used for storing temporary data. the stack pointer (sp) register always points to the top of the stack. it is implemented as two 8-bit register s that is accessible in the i/o memory space. data is pushed and popped from the stack usi ng the push and pop instructions. the stack is implemented as growing from higher memory locations to lower memory locations. this implies that a pushing data on the stack decreases the sp, and popping data off the stack increases the sp.the sp is automatically loaded after reset, and the initial value is the highest address of the internal sram. if the sp is changed, it must be set to point above address 0x2000 and it must be defined before any subroutine calls are executed or before interrupts are enabled. during interrupts or subroutine calls the return address is automatically pushed on the stack. the return address can be two or three bytes, de pending of the memory size of the device. for devices with 128k bytes or less of program memory the return address is two bytes, hence the stack pointer is decremented/incremented by two. for devices with more than 128k bytes of program memory, the return address is three by tes, hence the sp is decremented/incremented by three. the return address is popped of the stack when returning from interrupts using the reti instruction, and subroutine calls using the ret instruction. the sp is decremented by one when data is pus hed onto the stack with the push instruction, and incremented by one when data is popped off the stack using the pop instruction. to prevent corruption when updating the stack pointer from software, a write to spl will auto- matically disable interrupts for up to 4 instructions or until the next i/o memory write. 3.9 register file the register file consists of 32 x 8-bit general purpose registers. in order to achieve the required performance and flexib ility, the register file supp orts the followin g input/output schemes: ? one 8-bit output operand and one 8-bit result input ? two 8-bit output operands and one 8-bit result input ? two 8-bit output operands and one 16-bit result input ? one 16-bit output operand and one 16-bit result input
10 8210b?avr?04/10 xmega d figure 3-4. avr cpu general purpose working registers most of the instructions operating on the register file have direct access to all registers, and most of them are single cycle instructions. the register file is located in a separate address space, so the registers are not accessible as data memory. 3.9.1 the x-, y- and z- registers the registers r26..r31 have added functions besides their general-purpose usage. these registers can form 16-bit address pointers for addressing of the data memory. the three address registers is called the x-, y-, and z-register. the z-register can also be used as an address pointer to read from and/or write to the flash program memory, signature rows, fuses and lock bits. figure 3-5. the x-, y- and z-registers the lowest register address holds the least significant byte (lsb). in the different addressing modes these address registers have functions as fixed displacement, automatic increment, and automatic decrement (see the instruction set reference for details). 7 0 addr. r0 0x00 r1 0x01 r2 0x02 ? r13 0x0d general r14 0x0e purpose r15 0x0f working r16 0x10 registers r17 0x11 ? r26 0x1a x-register low byte r27 0x1b x-register high byte r28 0x1c y-register low byte r29 0x1d y-register high byte r30 0x1e z-register low byte r31 0x1f z-register high byte bit (individually) 7 r27 07 r26 0 x-register xh xl bit (x-register) 15 8 7 0 bit (individually) 7 r29 07 r28 0 y-register yh yl bit (y-register) 15 8 7 0 bit (individually) 7 r31 07 r30 0 z-register zh zl bit (z-register) 15 8 7 0
11 8210b?avr?04/10 xmega d 3.10 ramp and extended indirect registers in order to access program memory or data memory above 64k bytes, the address or address pointer must be more than 16-bits. this is done by concatenating one register to one of the x-, y- or z-registers, and this register then holds the most significant byte (msb) in a 24-bit address or address pointer. these registers are only available on devices with external bus interface and/or more than 64k bytes of program or data memory space. for these devices, only the number of bits required to address the whole program and data memory space in the device is implemented in the registers. 3.10.1 rampx, rampy and rampz registers the rampx, rampy and rampz registers are concatenated with the x-, y-, and z-registers respectively to enable indirect addressing of the whole data memory space above 64k bytes and up to 16m bytes. figure 3-6. the combined rampx + x, ram py + y and rampz + z registers when reading (elpm) and writing (spm) program memory locations above the first 128k bytes of the program memory, rampz is concatenated with the z-register to form the 24-bit address. lpm is not affected by the rampz setting. 3.10.2 rampd register this register is concatenated with the operand to enable direct addressing of the whole data memory space above 64k bytes. together ramp d and the operand will form a 24-bit address. figure 3-7. the combined rampd + k register 3.10.3 eind - extended indirect register eind is concatenated with the z-register to enable indirect jump and call to locations above the first 128k bytes (64k words) of the program memory. figure 3-8. the combined eind + z register bit (individually) 7 0 7 0 7 0 rampx xh xl bit (x-pointer) 23 16 15 8 7 0 bit (individually) 7 0 7 0 7 0 rampy yh yl bit (y-pointer) 23 16 15 8 7 0 bit (individually) 7 0 7 0 7 0 rampz zh zl bit (z-pointer) 23 16 15 8 7 0 bit (individually) 7 0 15 0 rampd k bit (d-pointer) 23 16 15 0 bit (individually) 7 0 7 0 7 0 eind zh zl bit (d-pointer) 23 16 15 8 7 0
12 8210b?avr?04/10 xmega d 3.11 accessing 16-bits registers the avr data bus is 8-bit so accessing 16-bit registers requires atomic operations. these regis- ters must be byte-accessed using two read or wr ite operations. due to this each 16-bit register uses an 8-bit register for temporary storing the hi gh byte during each write or read. a 16-bit reg- ister is connected to the 8-bit bus and a temporar y register using a 16-bit bus. this ensures that the low- and high-byte of 16-bit registers is always accessed simultaneously when reading or writing the register. for a write operation, the low-byte of the 16-bit register must be written before the high-byte. the low-byte is then written into the temporary register. when the high-byte of the 16-bit register is written, the temporary register is copied into the low-byte of the 16-bit register in the same clock cycle. for a read operation, the low-byte of the 16-bit register must be read before the high-byte. when the low byte register is read by the cpu, the high byte of the 16-bit register is copied into the temporary register in the same clock cycle as the low byte is read. when the high-byte is read, it is then read from the temporary register. interrupts can corrupt the timed sequence if the interrupt is triggered and try to access the same 16-bit register during an atomic 16-bit read/write operations. to prevent this, interrupts can be disabled when writing or reading 16-bit registers. the temporary registers can also be read and written directly from user software. 3.11.1 accessing 24- and 32-bit registers for 24- and 32-bit registers the read and write access is done in the same way as described for 16-bit registers, except there are two temporary registers for 24-bit register and three for 32-bit registers. the least significant byte must be wri tten first when doing a write, and read first when doing a read. 3.12 configuration change protection system critical i/o register settings are protected from accidental modification. the spm instruc- tion is protected from accidental execution, and the lpm instruction is protected when reading the fuses and signature row. this is handled globally by the configuration change protection (ccp) register. changes to the protected i/o regi sters or bit, or execution of the protected instructions are only possible af ter the cpu writes a signature to the ccp register. the different signatures is described the register description. there are 2 mode of operation, one for protected i/o registers and one for protected spm/lpm. 3.12.1 sequence for write operation to protected i/o registers 1. the application code writes the signature for change enable of protected i/o registers to the ccp register. 2. within 4 instruction cycles, the application code must write the appropriate data to the protected register. most protected registers also contain a write enable/change enable bit. this bit must be written to one in the same operation as the data is written. the pro- tected change is immediately disabled if t he cpu performs write operations to the i/o register or data memory, or if the instruction spm, lpm or sleep is executed.
13 8210b?avr?04/10 xmega d 3.12.2 sequence for execution of protected spm/lpm 1. the application code writes the signature for execution of protected spm/lpm to the ccp register. 2. within 4 instruction cycles, the application code must execute the appropriate instruc- tion. the protected change is immediately disabled if the cpu performs write operations to the data memory, or if sleep is executed. once the correct sig nature is written by the cp u, interrupts will be igno red for the configuration change enable period. any interrupt request (inc luding non-maskable interrupts) during the cpp period will set the corresponding interrupt flag as normal and the request is kept pending. after the cpp period any pending interrupts are executed according to their level and priority. 3.13 fuse lock for some system critical features it is possible to program a fuse to disable all changes in the associated i/o control registers. if this is done, it will not be po ssible to change the registers from the user software, and the fuse can only be reprogrammed using an external programmer. details on this are described in the datasheet module where this feature is available. 3.14 register description 3.14.1 ccp - configuration change protection register ? bit 7:0 - ccp[7:0] - configuration change protection the ccp register must be written with the correct signature to enable change of the protected i/o register or execution of the protected instruction for a maximum of 4 cpu instruction cycles. all interrupts are ignored during these cycles. after these cycles interrupts automatically handled again by the cpu, and any pending interrupts will be exec uted according to th eir level and prior- ity. when the protected i /o register signatur e is written, ccp[0] will read as one as long as the protected feature is enabled. similarly when the protected spm/lpm signature is written ccp[1] will read as one as long as the protected feature is enabled. ccp[7:2] will always be read as zero. table 3-1 on page 13 shows the signature for the various modes. bit 76543210 +0x04 ccp[7:0] ccp read/writewwwwwwww initial value 00000000 table 3-1. modes of cpu change protection signature group configuration description 0x9d spm protected spm/lpm 0xd8 ioreg protected io register
14 8210b?avr?04/10 xmega d 3.14.2 rampd - extended direct addressing register this register is concatenated with the operand for direct addressing (lds/sts) of the whole data memory space on devices with more than 64k bytes of data memory. when accessing data addresses below 64k bytes, this register is no t in use. this register is not available if the data memory including external memory is less than 64k bytes. ? bit 7:0 ? rampd[7:0]: extended direct addressing bits these bits holds the 8 msb of the 24-bit address created by rampd and the 16-bit operand. only the number of bits required to address t he available data memory is implemented for each device. unused bits will always read as zero. 3.14.3 rampx - extended x-pointer register this register is concatenated with the x-register for indirect addressing (ld/ldd/st/std) of the whole data memory space on devices with more t han 64k bytes of data memory. when access- ing data addresses below 64k bytes, this register is not in use. this register is not available if the data memory including external memory is less than 64k bytes. ? bit 7:0 ? rampx[7:0]: extended x-pointer address bits these bits holds the 8 msb of the 24-bit addr ess created by rampx and the 16-bit x-register. only the number of bits required to address t he available data memory is implemented for each device. unused bits will always read as zero. 3.14.4 rampy - extended y-pointer register this register is concatenated with the y-register for indirect addressing (ld/ldd/st/std) of the whole data memory space on devices with more t han 64k bytes of data memory. when access- ing data addresses below 64k bytes, this register is not in use. this register is not available if the data memory including external memory is less than 64k bytes. ? bit 7:0 ? rampy[7:0]: extended y-pointer address bits these bits hold the 8 msb of the 24-bit addres s created by rampy and the 16-bit y-register. only the number of bits required to address t he available data memory is implemented for each device. unused bits will always read as zero. bit 76543210 +0x08 rampd[7:0] rampd read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x09 rampx[7:0] rampx read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 00000000 bit 76543210 +0x0a rampy[7:0] rampy read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 00000000
15 8210b?avr?04/10 xmega d 3.14.5 rampz - extended z-pointer register this register is concatenated with the z-register for indirect addressing (ld/ldd/st/std) of the whole data memory space on devices with more than 64k bytes of data memory. rampz is concatenated with the z-register when reading (elpm) program memory locations above the first 64k bytes, and writing (spm) program memory locations above the first 128k bytes of the program memory. when accessing data addressees below 64k bytes, reading program memory locations below 64k bytes and writing program memory locations below 128k bytes, this register is not in use. this register is not available if the data memory including external memory and program mem- ory in the device is less than 64k bytes. ? bit 7:0 ? rampz[7:0]: extended z-pointer address bits these bits holds the 8 msb of the 24-bit address created by rampz and the 16-bit z-register. only the number of bits required to address the available data and program memory is imple- mented for each device. unused bits will always read as zero. 3.14.6 eind - extended indirect register this register is concatenated with the z-regi ster for enabling extended indirect jump (eijmp) and call (ecall) to the whole program memory space devices with more than 128k bytes of program memory. for jump or call to addressees below 128k bytes, this register is not in use. this register is not available if the program me mory in the device is less than 128k bytes. ? bit 7:0 - eind[7:0]: extended indirect address bits these bits holds the 8 msb of the 24-bit address created by eind and the 16-bit z-register. only the number of bits required to access the available program memory is implemented for each device. unused bits will always read as zero. 3.14.7 spl - stack pointer register low the sph and spl register pair represent the 16-bit value sp. the sp holds the stack pointer that point to the top of the stack. after reset, the stack pointer points to the highest internal sram address. when spl is written all interrupts are disabled for up to four instructions or until sph is also written. any pending interrupts will be execut ed according to their priority once inter- rupts are enabled again. only the number of bits required to address th e available data memory including external mem- ory, up to 64k bytes is impl emented for each devic e. unused bits will always read as zero. bit 76543210 +0x0b rampz[7:0] rampz read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 00000000 bit 76543210 +0x0c eind[7:0] eind read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 00000000
16 8210b?avr?04/10 xmega d note: 1. refer to specific device datasheets for exact initial values. ? bit 7:0 - sp[7:0]: stack pointer register low byte these bits hold the 8 lsb of the 16-bits stack pointer (sp). 3.14.8 sph - stack pointer register high note: 1. refer to specific device datasheets for exact initial values. ? bits 7:0 - sp[15:8]: stack pointer register high byte these bits hold the 8 msb of the 16-bits stack pointer (sp). 3.14.9 sreg - status register the status register (sreg) contains information about the result of the most recently executed arithmetic or logic instruction. ? bit 7 ? i: global interrupt enable the global interrupt enable bit must be set for interrupts to be enabled. if the global interrupt enable register is cleared, none of the interrupts are enabled independent of the individual interrupt enable settings. the i-bit is not cleared by hardware after an interrupt has occurred. the i-bit can be set and cleared by the application with the sei and cli instructions, as described in the ?instruction set description?. ? bit 6 ? t: bit copy storage the bit copy instructions bit load (bld) and bit store (bst) use the t-bit as source or destina- tion for the operated bit. a bit from a register in the register file can be copied into t by the bst instruction, and a bit in t can be copied into a bit in a register in the register file by the bld instruction. ? bit 5 ? h: half carry flag the half carry flag (h) indicates a half carry in some arithmetic operations. half carry is useful in bcd arithmetic. see the ?instruction set description? for detailed information. bit 76543210 +0x0d sp[7:0] spl read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value (1) 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 bit 76543210 +0x0e sp[15:8] sph read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value (1) 0/1 0/1 0/1 0/1 0/1 0/1 0/1 0/1 bit 76543210 +0x0f i t h s v n z c sreg read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 00000000
17 8210b?avr?04/10 xmega d ? bit 4 ? s: sign bit, s = n v the sign bit is always an exclusive or between the negative flag n and the two?s complement overflow flag v. see the ?instruction set description? for detailed information. ? bit 3 ? v: two?s complement overflow flag the two?s complement overflow flag (v) supports two?s complement arithmetics. see the ?instruction set description? for detailed information. ? bit 2 ? n: negative flag the negative flag (n) indicates a negative result in an arithmetic or logic operation. see the ?instruction set description? for detailed information. ? bit 1 ? z: zero flag the zero flag (z) indicates a zero result in an arithmetic or logic operation. see the ?instruction set description? for detailed information. ? bit 0 ? c: carry flag the carry flag (c) indicates a carry in an arithmetic or logic operation. see the ?instruction set description? for de tailed information. 3.15 register summary address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 reserved ? ? ? ? ? ? ? ? +0x01 reserved ? ? ? ? ? ? ? ? +0x02 reserved ? ? ? ? ? ? ? ? +0x03 reserved ? ? ? ? ? ? ? ? +0x04 ccp ccp[7:0] 13 +0x05 reserved ? ? ? ? ? ? ? ? +0x06 reserved ? ? ? ? ? ? ? ? +0x07 reserved ? ? ? ? ? ? ? ? +0x08 rampd rampd[7:0] 14 +0x09 rampx rampx[7:0] 14 +0x0a rampy rampy[7:0] 14 +0x0b rampz rampz[7:0] 15 +0x0c eind eind[7:0] 15 +0x0d spl spl[7:0] 15 +0x0e sph sph[7:0] 16 +0x0f sreg i t h s v n z c 16
18 8210b?avr?04/10 xmega d 4. memories 4.1 features ? flash program memory ? one linear address space ? in-system programmable ? self-programming and bootloader support ? application section for application code ? application table section for application code or data storage ? boot section for application code or bootloader code ? separate lock bits and protection for all sections ? data memory ? one linear address space ? single cycle access from cpu ? sram ? eeprom byte and page accessible optional memory mapping for direct load and store ? i/o memory configuration and status register s for all peripherals and modules four bit-accessible general purpose register for global variables or flags ? production signature row memory for factory programmed data device id for each microcontroller device type serial number for each device oscillator calibration bytes adc and temperature sensor calibration data ? user signature row one flash page in size can be read and written from software content is kept after chip erase 4.2 overview this section describes the different memories in xmega d. the avr architecture has two main memory spaces, the program memory and the da ta memory. executable code can only reside in the program memory, while data can be stored both in the program memory and the data memory. the data memory includes both sram, and eeprom memory for non-volatile data storage. all memory spaces are linear and requ ire no paging. non-volatile memory (nvm) spaces can be locked for further write and read/write operations. this prevents unrestricted access to the application software. a separate memory section contains the fuse bytes. these are used for setting important sys- tem functions, and write access is only possible from an external programmer. 4.3 flash program memory the xmega contains on-chip in-system reprog rammable flash memory for program storage. the flash memory can be accessed for read and write both from an external programmer through the pdi, or from application software running in the cpu.
19 8210b?avr?04/10 xmega d all avr instructions are 16 or 32 bits wide, and each flash location is 16 bits wide. the flash memory in xmega is organized in two main sections, the application section and the boot loader section, as shown in figure 4-1 on page 19 . the sizes of the different sections are fixed, but device dependent. these two sections have separate lock bits and can have different level of protection. the store program memory (spm) instruction used to write to the flash from the application software, will only operate when executed from the boot loader section. the application section contains an application table section with separate lock settings. this can be used for safe storage of non-volatile data in the program memory. figure 4-1. flash memory sections 4.3.1 application section the application section is the section of the flash that is used for storing the executable applica- tion code. the protection level for the application section can be selected by the boot lock bits for this section. the application section c an not store any boot loader code since the spm instruction cannot be executed from the application section. 4.3.2 application table section the application table section is a part of the application section of the flash that can be used for storing data. the size is identical to the boot loader section. the protection level for the application table section can be selected by the bo ot lock bits for this section. the possibilities application flash section 0x000000 end rww, end application start nrww, start boot loader flashend read-while-write section no read-while- write section application table flash section boot loader flash section
20 8210b?avr?04/10 xmega d for different protection levels on the applicat ion section and the application table section enable safe parameter storage in the program memory. if this section is not used for data, appli- cation code can be reside here. 4.3.3 boot loader section while the application section is used for storing the application code, the boot loader software must be located in the boot loader section since the spm instruction only can initiate program- ming when executing from the this section. the spm instruction can access the entire flash, including the boot loader section itself. the protection level for the boot loader section can be selected by the boot loader lock bits. if this section is not used for boot loader software, appli- cation code can be stored here. 4.3.4 production signature row the production signature row is a separate memory section for factory programmed data. it contains calibration data for fu nctions such as oscillators and analog modules. some of the cali- bration values will be automatically loaded to the corresponding mo dule or perip heral unit during reset. other values must be loaded from the signature row and written to the corresponding peripheral registers from software. for details on the calibration conditions such as temperature, voltage references etc. refer to device datasheet. the production signature row also contains a dev ice id that identify each microcontroller device type, and a serial number that is unique for each manufactured device. the serial number con- sist of the production lot number, wafer number, and wafer coordinates for the device. the production signature row can not be written or erased, but it can be read from both applica- tion software and external programming. 4.3.5 user signature row the user signature row is a separate memory section that is fully accessible (read and write) from application software and external programming. the user signature row is one flash page in size, and is meant for static user parameter storage, such as calibration data, custom serial numbers or identification numbers, random number seeds etc. this section is not erased by chip erase commands that erase the flash, and requires a dedicated erase command. this ensures parameter storage during multiple program/erase session and on-chip debug sessions. 4.4 fuses and lockbits the fuses are used to set important system function and can only be written from an external programming interface. the application software can read the fuses. the fuses are used to con- figure reset sources such as brown-out detector and watchdog and start-up configuration. the lock bits are used to set protection level on the different flash sections. they are used to block read and/or write access of the code. lock bits can be written from en external program- mer and from the application software to set a more strict protection level, but not to set a less strict protection level. chip erase is the only wa y to erase the lock bits. the lock bits are erased after the rest of the flash memory is erased. an unprogrammed fuse or lock bit will have the va lue one, while a progra mmed flash or lock bit will have the value zero. both fuses and lock bits are reprogrammable like the flash program memory.
21 8210b?avr?04/10 xmega d 4.5 data memory the data memory contains the i/o memory, internal sram, optionally memory mapped eeprom and external memory if available. the data memory is organized as one continuous memory section, as shown in figure 4-2 on page 22 . figure 4-2. data memory map i/o memory, eeprom and sram will always have the same start addresses for all xmega devices. external memory (if exist) will always start at the end of internal sram and end at address 0xffff. 4.6 internal sram the internal sram is mapped in the data memory space, always starting at hexadecimal address location 0x2000. sram is accessed from the cpu by using the load (ld/lds/ldd) and store (st/sts/std) instructions. 4.7 eeprom xmega has eeprom memory for non-vo latile data storage. it is a ddressable either in as a sep- arate data space (default), or it can be memory mapped and accessed in normal data space. the eeprom memory supports both byte and page access. 4.7.1 data memory mapped eeprom access the eeprom address space can optionally be m apped into the data memory space to allow highly efficient eeprom r eading and eeprom buffer loading. when doing this eeprom is accessible using load and store instructions . memory mapped eeprom will always start at hexadecimal address location 0x1000. 4.8 i/o memory the status and configuration registers for al l peripherals and modules, including the cpu, are addressable through i/o memory locations in the data memory space. all i/o locations can be accessed by the load (ld/lds/ldd) and store (st/sts/std) instructions, transferring data between the 32 general purpose registers in the register file and the i/o memory. the in and start/end address i/o memory (up to 4 kb) eeprom (up to 4 kb) internal sram 0x0000 0x1000 0xffff 0x2000 data memory
22 8210b?avr?04/10 xmega d out instructions can address i/o memory locations in the range 0x00 - 0x3f directly. in the address range 0x00 - 0x1f, specific bit manipulat ing and checking instructions are available. the i/o memory definition for an xmega device is shown in "register summary" in the device datasheet. 4.8.1 general purpose i/o registers the lowest 16 i/o memory addresses is reserved for general purpose i/o registers. these reg- isters can be used for storing information, and they are particularly useful for storing global variables and flags, as they are directly bit-accessible using the sbi, cbi, sbis, and sbic instructions. 4.9 memory timing read and write access to the i/o memory takes one cpu clock cycle. write to sram takes one cycle and read from sram takes two cycles. eeprom page load (write) takes one cycle and three cycles are required for read. for burst re ad, new data is available every second cycle. external memory has multi-cycle read and writ e. the number of cycles depends on type of memory. 4.10 device id each device has a three-byte device id which identifies the device. these registers identify atmel as the manufacturer of the device and th e device type. a separate register contains the revision number of the device. 4.11 io memory protection some features in the device is regarded to be crit ical for safety in some applications. due to this, it is possible to lock the io register related to the event system and the advanced waveform extensions. as long as the lock is enabled, all related io registers are locked and they can not be written from the application software. the lock registers themselves are protected by the configuration change protection mechanism, for details refer to ?configuration change protec- tion? on page 12 . 4.12 register descrip tion - nvm controller 4.12.1 addr2 - non-volatile memory address register 2 the addr2, addr1 and addr0 register s represents the 24-bit value addr. ? bit 7:0 - addr[23:16]: nvm address register byte 2 this register gives the data value byte 2 when accessing application and boot section. bit 76543210 +0x02 addr[23:16] addr2 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
23 8210b?avr?04/10 xmega d 4.12.2 addr1 - non-volatile memory address register 1 ? bit 7:0 - addr[15:8]: nvm address register byte 1 this register gives the address high byte when accessing either of the memory locations. 4.12.3 addr0 - non-volatile memory address register 0 ? bit 7:0 - addr[7:0]: nvm address register byte 0 this register gives the address low byte when accessing either of the memory locations. 4.12.4 data2 - non-volatile memory data register byte 2 the data2, data1 and addr0 registers represents the 24-bit value data. ? bit 7:0 - data[23:16]: nvm data register 2 this register gives the data value byte 2 when running crc check on application section, boot section or combined. 4.12.5 data1 - non-volatile memory data register 1 ? bit 7:0 - data[15:8]: nvm data register byte 1 this register gives the data value byte 1 when accessing application and boot section. bit 76543210 +0x01 addr[15:8] addr1 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x00 addr[7:0] addr0 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x06 data[23:16] data2 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x05 data[15:8] data1 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
24 8210b?avr?04/10 xmega d 4.12.6 data0 - non-volatile memory data register 0 ? bit 7:0 - data[7:0]: nvm data register byte 0 this register gives the data value byte 0 when accessing either of the memory locations. 4.12.7 cmd - non-volatile memory command register ? bit 7 - reserved this bit is unused and reserved fo r future use. for comp atibility with future devices, always write this bit to zero when this register is written. ? bit 6:0 -cmd[6:0]: nvm command these bits define the programming commands for the flash. bit six is set for external program- ming commands. see "memory programming datasheet" for programming commands. 4.12.8 ctrla - non-volatile memory control register a ? bit 7:1 - reserved bits these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 0 - cmdex: non-volatile memory command execute writing this bit to one will execut e the command in the cm d register. this bit is protected by the configuration change protection (ccp) mechanism, refer to section 3.12 ?configuration change protection? on page 12 for details on the ccp. bit 76543210 +0x04 data[7:0] data0 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x0a ? cmd[6:0] cmd read/write r r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x0b ? ? ? ? ? ? ?cmdexctrla read/write rrrrrrrs initial value 0 0 0 0 0 0 0 0
25 8210b?avr?04/10 xmega d 4.12.9 ctrlb - non-volatile memory control register b ? bit 7:4 - reserveds these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 3 - eemapen: eeprom data memory mapping enable writing this bit to one will enable data memo ry mapping of the eeprom section. the eeprom can then be accessed using load and store instructions. ? bit 2 - fprm: flash power reduction mode writing this bit to one will enable power saving for the flash memory. the section not being accessed will be turned off like in sl eep mode. if code is running from applic ation section, the boot loader section will be turned off and vice versa. if access to the section that is turned off is required, the cpu will be halted eq ually long to the start-up time from the idle sleep mode. this bit is protected by the configuration change protection (ccp) mechanism, refer to ?configura- tion change protection? on page 12 for details on the ccp. ? bit 1 - eprm: eeprom power reduction mode writing this bit to one will enable power saving for the eeprom memory. the eeprom will then be powered down equal to entering sleep mode. if access is required, the bus master will be halted equally long as the start-up time from id le sleep mode. this bit is protected by the configuration change protection (ccp) mechanism, refer to ?configuration change protection? on page 12 for details on the ccp. ? bit 0 - spmlock: spm locked the spm locked bit can be written to prevent all further self-programming. the bit is cleared at reset and cannot be cleared from software. this bit is protected by the configuration change protection (ccp) mechanism, refer to ?configuration change protection? on page 12 for details on the ccp. 4.12.10 intctrl - non-volatile memory interrupt control register ? bit 7:4 - reserved bits these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. bit 7 6 5 4 3 2 1 0 +0x0c ? ? ? ? eemapen fprm eprm spmlock ctrlb read/write r r r r r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x0d ? ? ? ? spmlvl[1:0] eelvl[1:0] intctrl read/write r r r r r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
26 8210b?avr?04/10 xmega d ? bit 3:2 - spmlvl[1:0]: spm ready interrupt level these bits enable the interrupt and select the interrupt level as described in ?interrupts and pro- grammable multi-level interrupt controller? on page 95 . the interrupt is a level interrupt, which will be triggered when the busy flag in the status is set to logical 0. since the interrupt is a level interrupt no te the following. the interrupt should not be enabled before triggering a nvm command, as the busy flag wont be set before the nvm command is triggered. since the interrupt trigger is a level interrupt, the interrupt should be disabled in the interrupt handler. ? bit 1:0 - eelvl[1:0]: eeprom ready interrupt level these bits enable the eeprom ready interrupt and select the interrupt level as described in ?interrupts and programmable multi-level interrupt controller? on page 95 . the interrupt is a level interrupt, which will be triggered when the bu sy flag in the status is set to logical 0. since the interrupt is a leve l interrupt note the following. the interrupt should not be enabled before triggering a nvm command, as the busy flag wont be set before the nvm command is triggered. since the interrupt trigger is a level interrupt, the interrupt should be disabled in the interrupt handler. 4.12.11 status - non-volatile memory status register ? bit 7 - nvmbusy: non-volatile memory busy the nvmbsy flag indicates whether the nvm me mory (flash, eeprom, lock-bits) is busy being programmed. once a program operation is started, this flag will be set and it remains set until the program operation is completed. he nvmbsy flag will automatically be cleared when the operation is finished. ? bit 6 - fbusy: flash section busy the fbusy flag indicate whether a flash operation (page erase or page write) is initiated. once a operation is started the fbusy flag is set, and the application section cannot be accessed. the fbusy bit will automatically be cleared when the oper ation is finished. ? bit 5:2 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 1 - eeload: eeprom page buffer active loading the eeload status flag indicates that the temporary eeprom page buffer has been loaded with one or more data bytes. immediately after an eeprom load command is issued and byte is written to nvmdr, or a memory mapped eeprom buffer load operation is performed, the eeload flag is set, and it remains set until an eeprom page write- or a page buffer flush oper- ation is executed. bit 7 6 5432 1 0 +0x04 busy fbusy ? ? ? ? eeload fload status read/write r r rrrr r r initial value 0 0 0000 0 0
27 8210b?avr?04/10 xmega d ? bit 0 - fload: flash page buffer active loading the fload flag indicates that the temporar y flash page buffer has been loaded with one or more data bytes. immediately after a flash load command has been issues and byte is written to nvmdr, the fload flag is set, and it remains set until an application- or boot page write- or a page buffer flush operation is executed. 4.12.12 lockbits - non-volatile memory lock bit register s this register is a direct mapping of the nvm lockbits into the io memory space, in order to enable direct read access from the application software. refer to ?lockbits - non-volatile memory lock bit register? on page 27 for description of the lock bits. bit 76543210 +0x07 blbb[1:0] blba[1:0] blbat[1:0] lb[1:0] lockbits read/write rrrrrrrr initial value 1 1 1 1 1 1 1 1
28 8210b?avr?04/10 xmega d 4.13 register descrip tion ? fuses and lockbit 4.13.1 fusebyte1 - non-volatile memory fuse byte1 - watchdog configuration ? bit 7:4 - wdwper[3:0]: watchdog window timeout period the wdwper fuse bits are used to set initia l value of the closed window for the watchdog timer in window mode. during reset these fuse bi ts are automatically written to the wper bits watchdog window mode control register, refer to section 11.7.2 ?wi nctrl ? window mode control register? on page 120 for details. ? bit 3:0 - wdper[3:0]: watchdog timeout period the wdper fuse bits are used to set initial value of the watchdog timeout period. during reset these fuse bits are automatically written to the per bits in the watchdog control register, refer to section 11.7.1 ?ctrl ? watchdog timer control register? on page 119 for details. 4.13.2 fusebyte2 - non-volatile memory fuse byte2 - reset configuration ? bit 7 - reserved this fuse bit is reserved. for co mpatibility with futu re devices, always write this bit to one when this register is written. ? bit 6 - bootrst: boot loader section reset vector the bootrst fuse can be programmed so the reset vector is pointing to the first address in the boot loader flash sect ion. in this case, the device will start executing from the from boot loader flash section after reset. ? bit 5:2 - reserved these fuse bits are reserved. for compatibility with future devices, always write these bits to one when this register is written. bit 7 6543210 +0x01 wdwper[3:0] wdper[3:0] fusebyte1 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0000000 bit 7 6 543210 +0x02 ?bootrst ? ? ? ? bodpd[1:0] fusebyte2 read/write r r/w r r r r r/w r/w initial value 1 1 111111 table 4-1. boot reset fuse bootrst reset address 0 reset vector = boot loader reset 1 reset vector = application reset (address 0x0000)
29 8210b?avr?04/10 xmega d ? bit 1:0 - bodpd[1:0]: bod operation in power-down mode the bodpd fuse bits set the bod operation mode in all sleep modes except idle mode. for details on the bod and bod operation modes refer to ?brown-out detection? on page 106 . 4.13.3 fusebyte4 - non-volatile memory fuse byte4 - start-up configuration ? bit 7:5 - reserved these fuse bits are reserved. for compatibility with future devices, always write these bits to one when this register is written. ? bit: 4 - rstdisbl - external reset disable this fuse can be programmed to disable the external reset pin functionality. when this is done pulling this pin low will not cause an external reset. ? bit 3:2 - startuptim e[1:0]: start-up time the startuptime fuse bits can be used to set at a programmable timeout period from all reset sources are released and until the internal reset is released from the delay counter. the delay is timed from the 1khz out put of the ulp oscillator, refer to section 9.3 ?reset sequence? on page 104 for details. ? bit 1 - wdlock: watchdog timer lock the wdlock fuse can be programmed to lock the watchdog timer configuration. when this fuse is programmed the watchdog timer configuration cannot be changed, and the watchdog timer cannot be disabled from the application software. when the wdlock fuse is pro- grammed the the watchdog timer is automatically enabled at reset. table 4-2. bod operation modes in sleep modes bodpd[1:0] description 00 reserved 01 bod enabled in sampled mode 10 bod enabled continuously 11 bod disabled bit 7 6 5 4 3 2 1 0 +0x04 ? ? ? rstdisbl startuptime[1:0] wdlock ? fusebyte4 read/write r r r r/w r/w r/w r/w r initial value 1 1 1 1 1 1 1 1 table 4-3. start-up time startuptime[1:0] 1khz ulp oscillator cycles 00 64 01 4 10 reserved 11 0
30 8210b?avr?04/10 xmega d ? bit 0 - reserved this fuse bit is reserved. for co mpatibility with futu re devices, always write this bit to one when this register is written. 4.13.4 fusebyte5 - non-volatile memory fuse byte 5 ? bit 7:6 - reserved these fuse bits are reserved. for compatibility with future devices, always write these bits to one when this register is written. ? bit 5:4 - bodact[1:0]: bo d operation in active mode the bodact fuse bits set the bod operation mode when the device is in active and idle mode of operation. for details on the bod and bod operation modes refer to ?brown-out detection? on page 84 . ? bit 3 - eesave: eeprom memory is preserved through the chip erase a chip erase command will normal ly erase the flash, eeprom and internal sram. if the eesave fuse is programmed, the eeprom is not erased during ch ip erase. in case eeprom is used to store data independen t of software revision, the eeprom can be pr eserved through chip erase. table 4-4. watchdog timer locking wdlock description 0 watchdog timer locked for modifications 1 watchdog timer not locked bit 7654 3 2 1 0 +0x05 ? ? bodact[1:0] eesave bodlevel[2:0] fusebyte5 read/write r r r/w r/w r/w r/w r/w r/w initial value 1 1 - - - - - - table 4-5. bod operation modes in active and idle mode bodact[1:0] description 00 reserved 01 bod enabled in sampled mode 10 bod enabled continuously 11 bod disabled table 4-6. eeprom memory through chip erase eesave description 0 eeprom is preserved during chip erase 1 eeprom is not preserved during chip erase
31 8210b?avr?04/10 xmega d changing of the eesave fuse bit takes effect im mediately after the write time-out elapses. hence, it is possible to update eesave and perform a chip erase according to the new setting of eesave without leaving and re-entering pr ogramming mode ? bit 2:0 - bodlevel[2:0] - brow n out detection voltage level the bodlevel fuse bits sets th e nominal bod level va lue. during power-on the device is kept in reset until the v cc level has reached the programmed bod level. due to this always ensure that the bod level is set lower than the v cc level, also if the bod is not enabled and used during normal operation, refer to section 9.4 ?reset sources? on page 104 for details. changing these fuse bits will have no effect until leavi ng programming mode. 4.13.5 lockbits - non-volatile memory lock bit register ? bit 7:6 - blbb[1:0]: boot lock bit boot loader section these bits indicate the locking mode for the boot loader section. even though the blbb bits are writable, they can only be written to a stricter locking. resetting the blbb bits is only possi- ble by executing a chip erase command. table 4-7. bod level nominal values, for actual values refer to the device datasheet. bodlevel normal bod level value (v) 111 1.6 110 1.8 101 2.0 100 2.2 011 2.4 010 2.6 001 2.8 000 3.0 bit 76543210 +0x07 blbb[1:0] blba[1:0] blbat[1:0] lb[1:0] lockbits read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 1 1 1 1 1 1 1 1
32 8210b?avr?04/10 xmega d ? bit 5:4 - blba[1:0]: boot lock bit application section these bits indicate the locking mode for the application section. even though the blba bits are writable, they can only be written to a stricter lo cking. resetting the blba bits is only possible by executing a chip erase command. table 4-8. boot lock bit for the boot loader section blbb[1:0] group configuration description 11 nolock no lock, no restrictions for spm and (e)lpm accessing the boot loader section. 10 wlock write lock, spm is not allowed to write the boot loader section 01 rlock read lock, (e)lpm executing from the application section is not allowed to read from the boot loader section. if the interrupt vectors ar e placed in the application section, interrupts are disabled while executing from the boot loader section. 00 rwlock read and write lock, spm is not allowed to write to the boot loader section and (e)lpm executing from the application section is not al lowed to read from the boot loader section. if the interrupt vectors ar e placed in the application section, interrupts are disabled while executing from the boot loader section table 4-9. boot lock bit for the application section blba[1:0] group conf iguration description 11 nolock no lock, no restrictions for spm and (e)lpm accessing the application section. 10 wlock write lock, spm is not allowed to write them application section 01 rlock read lock, (e)lpm executing from the boot loader section is not allowed to read from the application section. if the interrupt vectors ar e placed in the boot loader section, interrupts are disabled while executing from the application section. 00 rwlock read and write lock, spm is not allowed to write to the application section and (e)lpm executing from the boot loader section is not allowed to read from the application section. if the interrupt vectors ar e placed in the boot loader section, interrupts are disabled while executing from the application section.
33 8210b?avr?04/10 xmega d ? bit 3:2 - blbat[1:0]: boot lock bit application table section these bits indicate the locking mode for the application table section. even though the blbat bits are writable, they can only be written to a stricter locking. resetting the blbat bits is only possible by executing a chip erase command. ? bit 1:0 - lb[1:0]: lock bits these bits indicate the locking mode for the flash and eeprom in programming mode. these bits are writable only through an external prog ramming interface. resetting the lock bits is only possible by executing a chip erase command. table 4-10. boot lock bit for the application table section blbat[1:0] group configuration description 11 nolock no lock, no restrictions for spm and (e)lpm accessing the application table section. 10 wlock write lock, spm is not allowed to write the application ta b l e 01 rlock read lock, (e)lpm executing from the boot loader section is not allowed to read from the application table section. if the interrupt vectors ar e placed in the boot loader section, interrupts are disabled while executing from the application section. 00 rwlock read and write lock, spm is not allowed to write to the application table section and (e)lpm executing from the boot loader section is not allowed to read from the application table section. if the interrupt vectors ar e placed in the boot loader section, interrupts are disabled while executing from the application section. table 4-11. boot lock bit for the boot section lb[1:0] group configuration description 11 nolock3 no lock, no memory locks enabled. 10 wlock write lock, programming of the flash and eeprom is disabled for the programming interface. fuse bits are locked for write from the programming interface. 00 rwlock read and write lock, programming and read/verification of the fl ash and eeprom is disabled for the programming interface. the lock bits and fuses are locked for read and write from the programming interface.
34 8210b?avr?04/10 xmega d 4.14 register description - production signature row 4.14.1 rcosc2m - internal 2 mhz oscillator calibration register ? bit 7:0 - rcosc2m[7:0]: internal 2 mhz oscillator calibration value this byte contains the oscillator calibration value for the inte rnal 2 mhz oscillator. calibration of the oscillator is performed during production test of the device. du ring reset this value is auto- matically loaded into the calibration register b for the 2 mhz dfll, refer to ?calb - calibration register b? on page 92 for more details. 4.14.2 rcosc32k - internal 32.768 khz oscillator calibration register ? bit 7:0 - rcosc32k[7:0]: internal 32 khz oscillator calibration value this byte contains the oscillato r calibration value for the inter nal 32.768 khz oscillator. calibra- tion of the oscillator is perfor med during production test of the device. du ring reset this value is automatically loaded into the calibration register for the 32.768 khz oscillator, refer to ?rc32kcal - 32 khz oscillator ca libration register? on page 90 for more details. 4.14.3 rcosc32m - internal 32 mhz rc oscillator calibration register ? bit 7:0 - rcosc32m[7:0]: internal 32 mhz oscillator calibration value this byte contains the oscillator calibration value for the internal 32 mhz oscillator. calibration of the oscillator is performed during production test of the device. du ring reset this value is auto- matically loaded into the calibration register b for the 32 mhz dfll, refer to ?calb - calibration register b? on page 92 for more details. bit 7654 3 2 1 0 +0x00 rcosc2m[7:0] rcosc2m read/write r r r r r r r r initial value x x x x x x x x bit 7654 3 2 1 0 +0x02 rcosc32k[7:0] rcosc32k read/write r r r r r r r r initial value x x x x x x x x bit 7654 3 2 1 0 +0x03 rcosc32m[7:0] rcosc32m read/write r r r r r r r r initial value x x x x x x x x
35 8210b?avr?04/10 xmega d 4.14.4 lotnum0 - lot number register 0 lotnum0, lotnum1, lotnum2, lotnum3, lotnum4 and lotnum5 contains the lot number for each device. together with the wafer number and wafer coordinates this gives an unique identifier or serial number for the device. ? bit 7:0 - lotnum0[7:0] - lot number byte 0 this byte contains byte 0 of the lot number for the device. 4.14.5 lotnum1 - lot number register 1 ? bit 7:0 - lotnum1[7:0] - lot number byte 1 this byte contains byte 1 of the lot number for the device. 4.14.6 lotnum2 - lot number register 2 ? bit 7:0 - lotnum2[7:0] - lot number byte 2 this byte contains byte 2 of the lot number for the device. 4.14.7 lotnum3- lot number register 3 ? bit 7:0 - lotnum3[7:0] - lot number byte 3 this byte contains byte 3 of the lot number for the device. bit 7654 3 2 1 0 +0x08 lotnum0[7:0] lotnum0 read/write r r r r r r r r initial value x x x x x x x x bit 7654 3 2 1 0 +0x09 lotnum1[7:0] lotnum1 read/write r r r r r r r r initial value x x x x x x x x bit 7654 3 2 1 0 +0x0a lotnum2[7:0] lotnum2 read/write r r r r r r r r initial value x x x x x x x x bit 7654 3 2 1 0 +0x0b lotnum3[7:0] lotnum3 read/write r r r r r r r r initial value x x x x x x x x
36 8210b?avr?04/10 xmega d 4.14.8 lotnum4 - lot number register 4 ? bit 7:0 - lotnum4[7:0] - lot number byte 4 this byte contains byte 4 of the lot number for the device. 4.14.9 lotnum5 - lot number register 5 ? bit 7:0 - lotnum5[7:0] - lot number byte 5 this byte contains byte 5of the lot number for the device. 4.14.10 wafnum - wafer number register ? bit 7:0 - wafnum[7:0] - wafer number this byte contains the wafer number for each device. together with the lot number and wafer coordinates this gives an unique identifier or serial number for the device. 4.14.11 coordx0 - wafer coordinate x register 0 coordx0, coordx1, coordy0 and coordy1 contains the wafer x and y coordinates for each device. together with the lot number and wafer number this gives an unique identifier er or serial number for each devicei ? bit 7:0 - coordx0[7:0] - wafer coordinate x byte 0 this byte contains byte 0 of wafer coordinate x for the device. bit 7654 3 2 1 0 +0x0c lotnum4[7:0] lotnum4 read/write r r r r r r r r initial value x x x x x x x x bit 7654 3 2 1 0 +0x0d lotnum5[7:0] lotnum5 read/write r r r r r r r r initial value x x x x x x x x bit 7654 3 2 1 0 +0x10 wafnum[7:0] wafnum read/write r r r r r r r r initial value 0 0 0 x x x x x bit 7654 3 2 1 0 +0x12 coordx0[7:0] coordx0 read/write r r r r r r r r initial value x x x x x x x x
37 8210b?avr?04/10 xmega d 4.14.12 coordx1 - wafer coordinate x register 1 ? bit 7:0 - coordx0[7:0] - wafer coordinate x byte 1 this byte contains byte 1 of wafer coordinate x for the device. 4.14.13 coordy0 - wafer coordinate y register 0 ? bit 7:0 - coordy0[7:0] - wafer coordinate y byte 0 this byte contains byte 0 of wafer coordinate y for the device. 4.14.14 coordy1 - wafer coordinate y register 1 ? bit 7:0 - coordy1[7:0] - wafer coordinate y byte 1 this byte contains byte 1 of wafer coordinate y for the device 4.14.15 adcacal0 - adca calibration register 0 adcacal0 and adcacal1 contains the calibrati on value for the analog to digital converter a (adca). calibration of the analog to digital converters are done during production test of the device. the calibration bytes are not loaded automatically into the adc calibration registers, and this must be done from software. ? bit 7:0 - adcacal0[7:0] - adca calibration byte 0 this byte contains byte 0 of the adca calibration data, and must be loaded into the adca call register. bit 7654 3 2 1 0 +0x13 coordx1[7:0] coordx1 read/write r r r r r r r r initial value x x x x x x x x bit 7654 3 2 1 0 +0x14 coordy0[7:0] coordy0 read/write r r r r r r r r initial value x x x x x x x x bit 7654 3 2 1 0 +0x15 coordy1[7:0] coordy1 read/write r r r r r r r r initial value x x x x x x x x bit 7654 3 2 1 0 +0x20 adcacal0[7:0] adcacal0 read/write r r r r r r r r initial value x x x x x x x x
38 8210b?avr?04/10 xmega d 4.14.16 adcacal1 - adca calibration register 1 ? bit 7:0 - adcacal1[7:0] - adca calibration byte 1 this byte contains byte 1 of the adca calibration data, and must be loaded into the adca calh register. 4.14.17 tempsense0 - temperature se nsor calibration register 0 tempsense0 and tempsense1 contains the 12-b it adca value from a temperature mea- surements done with the internal temperature sensor. the measurements is done in production test at 85c and can be used for single- or multi-point temperature sensor calibration. ? bit 7:0 - tempsense0[7:0] - temper ature sensor calibration byte 0 this byte contains the byte 0 (8 lsb) of the temperature measurement. 4.14.18 tempsense1 - temperature se nsor calibration register 1 ? bit 7:0 - tempsense1[7:0] - temper ature sensor calibration byte 1 this byte contains byte 1 of the temperature measurement. 4.15 register description ? general purpose i/o memory 4.15.1 gpiorn ? general purpose i/o register n this is a general purpose register that can be used to store data such as global variables in the bit accessible i/o memory space. bit 7654 3 2 1 0 +0x21 adcacal1[7:0] adcacal1 read/write r r r r r r r r initial value x x x x x x x x bit 7654 3 2 1 0 +0x2e tempsense0[7:0] tempsense0 read/write r r r r r r r r initial value x x x x x x x x bit 7654 3 2 1 0 +0x2f tempsense1[7:0] tempsense1 read/write r r r r r r r r initial value 0 0 0 0 x x x x bit 76543210 +n gpiorn[7:0] gpiorn read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
39 8210b?avr?04/10 xmega d 4.16 register descrip tion ? mcu control 4.16.1 devid0 - mcu de vice id register 0 the devid0, devid1 and devid2 contains the 3-byte identification that identify each micro- controller device type. for details on the ac tual id refer to the device datasheet. ? bit 7:0 - devid0[7:0]: mcu device id byte 1 this byte will always be read as 0x1e. this indi cates that the device is manufactured by atmel 4.16.2 devid1 - mcu de vice id register 1 ? bit 7:0 - devid[7:0]: mcu device id byte 1 byte 1 of the device id indicates the flash size of the device. 4.16.3 devid2 - mcu de vice id register 2 ? bit 7:0 - devid2[7:0]: mcu device id byte 2 byte 0 of the device id indicates the device number. 4.16.4 revid - mcu revision id ? bit 7:4 - reserved these bits are reserved and will always read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 3:0 - revid[3:0]: mcu revision id these bits contains the device revision. 0=a, 1=b and so on. bit 76543210 +0x00 devid0[7:0] devid0 read/write rrrrrrrr initial value 1/0 1/0 1/0 1/0 1/0 1/0 1/0 1/0 bit 76543210 +0x01 devid1[7:0] devid1 read/write rrrrrrrr initial value 1/0 1/0 1/0 1/0 1/0 1/0 1/0 1/0 bit 76543210 +0x02 devid2[7:0] devid2 read/write rrrrrrrr initial value 1/0 1/0 1/0 1/0 1/0 1/0 1/0 1/0 bit 76543210 +0x03 ? ? ? ? revid[3:0] revid read/write rrrrrrrr initial value 1/0 1/0 1/0 1/0 1/0 1/0 1/0 1/0
40 8210b?avr?04/10 xmega d 4.16.5 mcucr ? mcu control register ? bit 7:0 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. 4.16.6 evsyslock ? event system lock register ? bit 7:1 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 0 - evsys0lock: writing this bit to one will lock all registers in th e event system related to event channe ls 0 to 3 for further modifications. the following regist ers in the event system are locked: ch0mux, ch0ctrl, ch1mux, ch1ctrl, ch2mux, ch2ctrl , ch3mux, ch3ctrl. this bit is pro- tected by the configuration change protection mechanism, for details refer to section 3.12 ?configuration change protection? on page 12 . 4.16.7 awexlock ? advanced waveform extension lock register ? bit 7:1 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 0 - awexclock: advanced waveform extension lock for tcc0 writing this bit to one will lock all registers in the awexc module for timer/counter c0 for fur- ther modifications. this bit is protected by th e configuration change protection mechanism, for details refer to section 3.12 ?configuration change protection? on page 12 . bit 76543210 +0x06 ? ? ? ? ? ? ? ? mcucr read/write rrrrrrrr initial value 0 0 0 0 0 0 0 0 bit 7654321 0 +0x08 ? ? ? ? ? ? ? evsys0lock evsyslock read/write rrrrrrr r/w initial value 0 0 0 0 0 0 0 0 bit 7654321 0 +0x09 ? ? ? ? ? ? ? awexclock awexlock read/write rrrrrrr r/w initial value 0 0 0 0 0 0 0 0
41 8210b?avr?04/10 xmega d 4.17 register summar y - nvm controller 4.18 register summar y - fuses and lockbits address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 addr0 nvm address byte 0 25 +0x01 addr1 nvm address byte 1 25 +0x02 addr2 nvm address byte 2 25 +0x03 reserved ? ? ? ? ? ? ? ? +0x04 data0 nvm data byte 0 26 +0x05 data1 nvm data byte 1 26 +0x06 data2 nvm data byte 2 26 +0x07 reserved ? ? ? ? ? ? ? ? +0x08 reserved ? ? ? ? ? ? ? ? +0x09 reserved ? ? ? ? ? ? ? ? +0x0a cmd ?cmd[6:0]26 +0x0b ctrla ? ? ? ? ? ? ?cmdex27 +0x0c ctrlb ? ? ? ? eemapen fprm eprm spmlock 27 +0x0d intctrl ? ? ? ? spmlvl[1:0] eelvl[1:0] 28 +0x0e reserved ? ? ? ? ? ? ? ? +0x0f status nvmbusy fbusy ? ? ? ? eeload fload 28 +0x10 lockbits blbb[1:0] blba[1:0] blbat[1:0] lb[1:0] 29 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x01 fusebyte1 wdwper3:0] wdper[3:0] 30 +0x02 fusebyte2 ? bootrst ? ? ? ? bodpd[1:0] 30 +0x03 reserved ? ? ? ? ? ? ? ? +0x04 fusebyte4 ? ? ? rstdisbl startuptime[1:0] wdlock ?31 +0x05 fusebyte5 ? ? bodact[1:0] eesave bodlevel[2:0] 32 +0x06 reserved ? ? ? ? ? ? ? ? +0x07 lockbits blbb[1:0] blba[1:0] blbat[1:0] lb[1:0] 34
42 8210b?avr?04/10 xmega d 4.19 register summary - production signature row address auto load name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 yes rcosc2m rcosc2m[7:0] 36 +0x01 reserved +0x02 yes rcosc32k rcosc32k[7:0] 36 +0x03 yes rcosc32m rcosc32m[7:0] 37 +0x04 reserved +0x05 reserved +0x06 reserved +0x07 reserved +0x08 no lotnum0 lotnum0[7:0] 37 +0x09 no lotnum1 lotnum1[7:0] 37 +0x0a no lotnum2 lotnum2[7:0] 37 +0x0b no lotnum3 lotnum3[7:0] 38 +0x0c no lotnum4 lotnum4[7:0] 38 +0x0d no lotnum5 lotnum5[7:0] 38 +0x0e reserved +0x0f reserved +0x10 no wafnum wafnum[7:0] 38 +0x11 reserved +0x12 no coordx0 coordx0[7:0] 39 +0x13 no coordx1 coordx1[7:0] 39 +0x14 no coordy0 coordy0[7:0] 39 +0x15 no coordy1 coordy1[7:0] 39 +0x16 reserved +0x17 reserved +0x18 reserved +0x19 reserved +0x1a reserved +0x1b reserved +0x1c reserved +0x1d reserved +0x0e reserved +0x1e reserved +0x20 no adcacal0 adcacal0[7:0] 39 +0x21 no adcacal1 adcacal1{7:0] 40 +0x22 reserved +0x23 reserved +0x24 reserved +0x25 reserved +0x26 reserved +0x27 reserved +0x28 reserved +0x29 reserved +0x2a reserved +0x2b reserved +0x2c reserved +0x2d reserved +0x2e no tempsense0 tempsense[7:0] 41 +0x2f no tempsense1 tempsene[11:8] 41 +0x34 reserved +0x35 reserved +0x36 reserved +0x37 reserved +0x38 reserved +0x39 reserved 0x3a reserved +0x3b reserved +0x3c reserved +0x3d reserved +0x3e reserved
43 8210b?avr?04/10 xmega d 4.20 register summary - gener al purpose i/o registers 4.21 register summary - mcu control 4.22 interrupt vector summary - nvm controller address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 gpior0 gpior[7:0] 42 +0x01 gpior1 gpior[7:0] 42 +0x02 gpior2 gpior[7:0] 42 +0x03 gpior3 gpior[7:0] 42 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 devid0 devid0[7:0] 43 +0x01 devid1 devid1[7:0] 43 +0x02 devid2 devid2[7:0] 43 +0x03 revid ? ? ? ? revid[3:0] 43 +0x05 reserved ? ? ? ? ? ? ? ? +0x06 mcucr ? ? ? ? ? ? ? ?48 +0x07 reserved ? ? ? ? ? ? ? ? +0x08 evsyslock ? ? ? ? ? ? ? evsys0lock +0x09 awexlock ? ? ? ? ? ? ?awexclock +0x0a reserved ? ? ? ? ? ? ? ? +0x0b reserved ? ? ? ? ? ? ? ? table 4-12. nvm interrupt vectors and their word offset address from the nvm controller interrupt base offset source interrupt description 0x00 spm_vect non-volatile memory spm interrupt vector 0x02 ee_vect non-volatile memory eeprom interrupt vector
44 8210b?avr?04/10 xmega d 5. event system 5.1 features ? inter peripheral commun ication and signalling ? cpu independent operation ? 4 event channels allows for up to 4 signals to be rout ed at the same time ? 100% predictable timing between peripherals ? events can be generated by ? timer/counters (tcxn) ? real time counter (rtc) ? analog to digital converters (adcx) ? analog comparators (acx) ? ports (portx) ? system clock (clk sys ) ? events can be used by ? timer/counters (tcxn) ? analog to digital converters (adcx) ?ports ? advanced features ? manual event generati on from software (cpu) ? quadrature decoding ? digital filtering ? operative in active and idle mode 5.2 overview the event system is a set of features for inter peripheral communication. it enables the possibil- ity for a change of state in one peripheral to automatically trigger actions in other peripherals. the change of state in a peripheral that will trigger actions in other periphe rals is configurable in software. it is a simple, but power ful system as it allows for auto nomous control of peripherals without any use of interrupt, cpu resource. the indication of a change of state in a peripheral is referred to as an event. the events are passed between peripherals using a dedicated routing network called the event routing net- work. figure 5-1 on page 45 shows a basic block diagram of the event system with the event routing network and the peripherals that are connected.
45 8210b?avr?04/10 xmega d figure 5-1. event system overview and connected peripherals the cpu is not part of the event system, but it indicates that it is possible to manually generate events from software or by using the on-chip debug system. the event system works in active and idle mode. 5.3 events in the context of the event system, an indication that a change of state within a peripheral has occurred is called an event. there are two main types of events: signaling events and data events. signaling events only indicate a change of state while data events contain additional information on the event. the peripheral from where the event origin is called the event generator. within each periph- eral, for example a timer/counter, there can be several event sources, such as a timer compare match or timer overflow. the peripheral using th e event is called the event user, and the action that is triggered is called the event action. figure 5-2. example of event source, generator, user and action adcx event routing network portx cpu acx rtc t/cxn ircom clk sys event routing network | compare match over-/underflow error timer/counter channel sweep single conversion adc event generator event source event user event action event action selection
46 8210b?avr?04/10 xmega d events can be manually generated by writing to the strobe and data registers. 5.3.1 signaling events signaling events are the most basic type of even ts. a signaling event does not contain any infor- mation apart from the indication of a change in a peripheral. most peripherals can only generate and use signaling events. unless otherwise stated, all occurrences of the word 'event' is to be understood as a signaling event. 5.3.2 data events data events differ from signaling events in that they contain additional information that event users can decode to decide event actions based on the receiver information. the event routing network can route all events to all event users. event users that are only meant for using signaling events have limited de code capabilities and ca nnot fully utilize data. how event users decode data events is shown in table 5-1 on page 46 . event users that can utilize data events can also use signaling events. th is is configurable, and is described in the datasheet module for each peripheral. 5.3.3 manually generating events events can be generated manually by writing the data and strobe register. this can be done from software, and by accessing the registers directly during on-chip debugging. the data reg- ister must be written first since writing the st robe register triggers the operation. the data and strobe registers contain one bit for each event channel. bit n corresponds to event chan- nel n. it is possible to generate events on several channels at the same time by writing to several bit locations at once. manually generated events last for one clock cycle and will overwrite events from other event during that clock cycle. when manually generating even ts, event channels where no events are entered will let othe r events through. table 5-1 on page 46 shows the different events, how they can be manually generated and how they are decoded. 5.4 event routing network the event routing network routes events between peripherals. it consists of eight multiplexers (chnmux), where events from all event sources are routed into all multiplexers. the multiplex- ers select which event is routed back as input to all peripherals. the output from a multiplexer is referred to as an event channel. for each peripheral it is selectable if and how incoming events should trigger event actions. details on these ar e described in the datasheet for each peripheral. the event routing network is shown on figure 5-3 on page 47 . table 5-1. manually generated events and decoding of events strobe data data event user signaling event user 0 0 no event no event 0 1 data event 01 no event 1 0 data event 02 signaling event 1 1 data event 03 signaling event
47 8210b?avr?04/10 xmega d figure 5-3. event routing network having four multiplexers means that it is possible to route up to four events at the same time. it is also possible to route one event through several multiplexers. not all xmega parts contain all peripherals. this only means that peripheral is not available for generating or using events. the network configuration itself is compatible between all devices. 5.5 event timing an event normally lasts for one peripheral cloc k cycle, but some event sources, such as low level on an i/o pin, will generate events continuously. details on this are described in the (48) porta portb portc portd porte portf adca (portf) tcf0 (8) (porte) tce0 (portd) tcd0 (portc) tcc0 tcc1 (8) (8) (8) (8) (8) (16) (8) (7) (4) (8) (8) ac0 ac1 rtc (8) (8) (8) (8) (8) (8) ch0mux[7:0] ch1mux[7:0] ch2mux[7:0] ch3mux[7:0] ch0ctrl[7:0] ch1ctrl[7:0] ch2ctrl[7:0] ch3ctrl[7:0] event channel 3 event channel 2 event channel 1 event channel 0 (8)
48 8210b?avr?04/10 xmega d datasheet for each peripheral, but unless stated, an event lasts for one peripheral clock cycle only. it takes maximum two clock cycles from an event is generated until the event actions in other peripherals is triggered. it take s one clock cycle from the event happens until it is registered by the event routing network on the first positive clock edge. it takes an additional clock cycle to route the event through the event channel to the event user. 5.6 filtering each event channel includes a digital filter. when this is enabled for an event channel, an event must be sampled with the same value for configurable number of system clock cycles before it is accepted. this is primarily intended for pin change events. 5.7 quadrature decoder the event system includes one quadrature decoder (qdec). this enables the event system to decode quadrature input on i/o pins, and send data events that a timer/counter can decode to trigger the appropriate event action: count up, count down or index/reset. table 5-2 on page 48 summarizes which quadrature decoder data events are available, how they are decoded, and how they can be generated. the qdec and related features, control and status register are available for event channel 0. 5.7.1 quadrature operation a quadrature signal is characterized by having two square waves phase shifted 90 degrees rela- tive to each other. rotational movement can be measured by counting the edges of the two waveforms. the phase relationship between the two square waves determines the direction of rotation. figure 5-4. quadrature signals from a rotary encoder table 5-2. quadrature decoder data events strobe data data event user signaling event user 0 0 no event no event 0 1 index/reset no event 1 0 count down signaling event 1 1 count up signaling event 00 10 11 01 qdph0 qdph90 qdindx forward direction backward direction 01 11 10 00 1 cycle / 4 states qdph0 qdph90 qdindx
49 8210b?avr?04/10 xmega d figure 5-4 shows typical quadrature signals from a rotary encoder. the signals qdph0 and qdph90 are the two quadrature signals. when qdph90 leads qdph0, the rotation is defined as positive or forward. when qdph0 leads qdph 90, the rotation is defined as negative, or reverse. the concatenation of the two phase signals is called the quadrature state or the phase state. in order to know the absolute rotary displacement a third index signal (qdindx) can be used. this gives an indication once per revolution. 5.7.2 qdec setup for a full qdec setup th e following is required: ? i/o port pins - quadrature signal input ? the event system - quadrature decoding ? a timer/counter - up, down and optional index count the following procedure should be used for qdec setup: ? choose two successive pins on a port as qdec phase inputs. ? set pin direction for qdph0 and qdph90 as input. ? set pin configuration for qdph0 and qdph90 to low level sense. ? select qdph0 pin as multiplexer input for an event channel, n. ? enable quadrature decoding and digital filtering in the event channel. ? optional: a. setup qdec index (qindx). b. select a third pin for qindx input. c. set pin direction for qindx as input. d. set pin configuration for qindx to sense both edges. e. select qindx as multiplexer input for event channel n+1 f. set the quadrature index enable bit in event channel n+1. g. select the index recognition mode for event channel n+1. ? set quadrature decoding as event action for a timer/counter. ? select event channel n as event source the timer/counter. ? set the period register of the timer/counter to ('line count' * 4 - 1). (the line count of the quadrature encoder). ? enable the timer/counter by se tting clksel to a clksel_div1. the angle of a quadrature encoder attached to qdph0, qdph90 (and qindx) can now be read directly from the timer/counter count register. if the count register is different from bottom when the index is recognized, the timer/counter erro r flag is set. similarly the error flag is set if the position counter passes bottom without the recognition of the index.
50 8210b?avr?04/10 xmega d 5.8 register description 5.8.1 chnmux ? event channel n multiplexer register . ? bit 7:0 - chnmux[7:0]: channel multiplexer these bits select the event source according to table 5-3 . this table is valid for all xmega devices regardless of if the peripheral is present or not. selecting event sources from peripher- als that are not pres ent will give the same result as when th is register is zero. when this register is zero no events are routed through. manua lly generated events will override the chnmux and be routed to the event channel even if this register is zero. bit 76543210 chnmux[7:0] chnmux read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 00000000 table 5-3. chnmux[7:0] bit settings chnmux[7:4] chnmux[3:0] group configuration event source 0000 0000 none (manually generated events only) 0000 0001 (reserved) 0000 0 0 1 x (reserved) 0000 0 1 x x (reserved) 0000 1000rtc_ovf rtc overflow 0000 1001rtc_cmp rtc compare march 0000 1 0 1 x (reserved) 0000 1 1 x x (reserved) 0001 0000aca_ch0 aca channel 0 0001 0001aca_ch1 aca channel 1 0001 0010aca_win aca window 0001 0011 (reserved) 0001 0 1 x x (reserved) 0001 1 x x x (reserved) 0010 0 0 n adca_chn adca channel n (n =0, 1, 2 or 3) 0010 0 1 x (reserved) 0010 1 x x x (reserved) 0011 xxxx (reserved) 0100 xxxx (reserved) 0101 0 n porta_pinn (1) porta pin n (n= 0, 1, 2 ... or 7) 0101 1 n portb_pinn (1) portb pin n (n= 0, 1, 2 ... or 7) 0110 0 n portc_pinn (1) portc pin n (n= 0, 1, 2 ... or 7) 0110 1 n portd_pinn (1) portd pin n (n= 0, 1, 2 ... or 7)
51 8210b?avr?04/10 xmega d note: 1. the description of how ports generate events are described in ?port event? on page 108 . 5.8.2 chnctrl ? event channel n control register . ? bit 7 - reserved this bit is reserved and will a lways be read as zero. for compat ibility with future devices, always write this bit to zero when this register is written. 0111 0 n porte_pinn (1) porte pin n (n= 0, 1, 2 ... or 7) 0111 1 n portf_pinn (1) portf pin n (n= 0, 1, 2 ... or 7) 1000 m prescaler_m clk per divide by m (m=1 to 32768) 1001 xxxx (reserved) 1010 xxxx (reserved) 1011 xxxx (reserved) 1100 0 e see table 5-4 timer/counter c0 event type e 1100 1 e see table 5-4 timer/counter c1 event type e 1101 0 e see table 5-4 timer/counter d0 event type e 1101 1 x x x (reserved) 1110 0 e see table 5-4 timer/counter e0 event type e 1110 1 x x x (reserved) 1111 0 e see table 5-4 timer/counter f0 event type e 1111 1 x x x (reserved) table 5-4. timer/counter events t/c event e group configuration event type 0 0 0 tcxn_ovf over-/underflow (x = c, d, e or f) (n= 0 or 1) 0 0 1 tcxn_err error (x = c, d, e or f) (n= 0 or 1) 0 1 x (reserved) 1 0 0 tcxn_cca capture or compare a (x = c, d, e or f) (n= 0 or 1) 1 0 1 tcxn_cca capture or compare b (x = c, d, e or f) (n= 0 or 1) 1 1 0 tcxn_cca capture or compare c (x = c, d, e or f) (n= 0 or 1) 1 1 1 tcxn_cca capture or compare d (x = c, d, e or f) (n= 0 or 1) table 5-3. chnmux[7:0] bit settings (continued) chnmux[7:4] chnmux[3:0] group configuration event source bit 76543210 ? qdirm[1:0] qdien qden digfilt[2:0] chnctrl read/write r r/w r/w r/w r/w r/w r/w r/w initial value00000000
52 8210b?avr?04/10 xmega d ? bit 6:5 - qdirm[1:0]: quadrature decode index recognition mode these bits determine the quadrature state fo r the qdph0 and qdph90 signals where a valid index signal is recognized and the counter index data event is given according to table 5-5 on page 52 . these bits is only needed to set when a quadrature encoed with a connected index sig- nal is used. these bits are only availa ble for ch0ctrl and ch2ctrl ? bit 4 - qdien: quadrature decode index enable when this bit is set the event channel will be used as qdec index so urce, and the index data event will be enabled. these bit is only available for ch0ctrl and ch2ctrl. ? bit 3 - qden: quadrature decode enable setting this bit enables qdec operation. these bits is only available for ch0ctrl and ch2ctrl. ? bit 2:0 - digfilt[2:0]: digital filter coefficient these bits define the length of digital filtering used. events will be passed through to the event channel only when the event source has been acti ve and sampled with the same level for a a number of peripheral clock for the number of cycles as defined by digfilt. table 5-5. qdirm bit settings qdirm[1:0] index recognition state 0 0 {qdph0, qdph90} = 0b00 0 1 {qdph0, qdph90} = 0b01 1 0 {qdph0, qdph90} = 0b10 1 1 {qdph0, qdph90} = 0b11 table 5-6. digital filter co efficient values digfilt[2:0] group configuration description 000 1sample 1 sample 001 2samples 2 samples 010 3samples 3 samples 011 4samples 4 samples 100 5samples 5 samples 101 6samples 6 samples 110 7samples 7 samples 111 8samples 8 samples
53 8210b?avr?04/10 xmega d 5.8.3 strobe ? event strobe register a single event lasting for one peri pheral clock cycl e will be generated. ? bit 7:4 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bit to zero when this register is written. ? bit 3:0 - strobe[3:0] - event strobe bit register if any of the strobe bit is unequal to zero or simply written, each event channel will be set according to the strobe[n] and corresponding data[n] bit setting. 5.8.4 data ? event data register this register must be written before the strobe register, for details see ?strobe ? event strobe register? on page 53. ? bit 7:4 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 3:0 - data[3:0] - event data bit register any of the data bits contains the data value when manually generating a data event. bit 76543210 +0x10 ? ? ? ? strobe[3:0] strobe read/writerrrrr/wr/wr/wr/w initial value 00000000 bit 76543210 +0x11 ? ? ? ? data[3:0] data read/writerrrrr/wr/wr/wr/w initial value 00000000
54 8210b?avr?04/10 xmega d 5.9 register summary address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 ch0mux ch0mux[7:0] 50 +0x01 ch1mux ch1mux[7:0] 50 +0x02 ch2mux ch2mux[7:0] 50 +0x03 ch3mux ch3mux[7:0] 50 +0x04 reserved +0x05 reserved +0x06 reserved +0x07 reserved +0x08 ch0ctrl ? qdirm[1:0] qdien qden digfilt[2:0] 51 +0x09 ch1ctrl ? ? ? ? ? digfilt[2:0] 51 +0x0a ch2ctrl ? ? ? ? ? digfilt[2:0] 51 +0x0b ch3ctrl ? ? ? ? ? digfilt[2:0] 51 +0x0c reserved +0x0d reserved +0x0e reserved +0x0f reserved +0x10 strobe ? ? ? ? strobe[3:0] 53 +0x11 data ? ? ? ? data[3:0] 53
55 8210b?avr?04/10 xmega d 6. system clock and clock options 6.1 features ? fast start-up time ? safe run-time clock switching ? internal oscillators: ? 32 mhz run-time cal ibrated rc oscillator ? 2 mhz run-time calibrated rc oscillator ? 32.768 khz calibrated rc oscillator ? 32 khz ultra low power (ulp) oscillator with 1 khz output ? external clock options ? 0.4 - 16 mhz crystal oscillator ? 32.768 khz crystal oscillator ? external clock ? pll with internal and external clock options with 1 to 31x multiplication ? clock prescalers with 1 to 2048x division ? fast peripheral clock running at 2 and 4 times the cpu clock speed ? automatic run-time calibration of internal oscillators ? crystal oscillator failure detection 6.2 overview xmega has a flexible clock system, supporting a large number of clock sources. it incorporates both accurate integrated oscillators, and external crystal oscillators and resonators. a high fre- quency phase locked loop (pll) and clock prescalers can be used to generate a wide range of clock frequencies. a calibration feature (dfll) is available, and can be used for automatic run- time calibration of the internal oscillators. a crystal oscilla tor failure monitor can be enabled to issue a non-maskable interrupt and switch to inte rnal oscillator if the external oscillator fails. after reset, the device will always start up running from the 2 mhz internal oscillator. during nor- mal operation, the system clock source and prescalers can be changed from software at any time. figure 6-1 on page 56 presents the principal clock system in the xmega. all of the clocks do not need to be active at a given time. the clocks to the cpu and peripherals can be stopped using sleep modes and power reduction registers as described in ?power management and sleep? on page 74 .
56 8210b?avr?04/10 xmega d figure 6-1. the clock system, clock sources and clock distribution 6.3 clock distribution figure 6-1 on page 56 presents the principal clock distribution in the xmega. 6.3.1 system clock - clk sys the system clock is the output from the main system clock selection. this is fed into the pres- calers that are used to generate all inte rnal clocks except th e asynchronous clock. 6.3.2 cpu clock - clk cpu the cpu clock is routed to the cpu and non-vo latile memory. halting the cpu clock inhibits the cpu from executing instructions. 32 khz int. ulp system clock prescalers 2 mhz int. osc. 32 mhz int. osc. 32.768 khz int. osc. watchdog timer brown-out detection system clock multiplexer real time counter peripherals ram avr cpu non-volatile memory clk per clk sys clk per4 clk per2 clk cpu clk rtc external clock pll tosc2 tosc1 xtal2 xtal1 div4 div32 div32 xtal 32.768 khz xtal 0.4?16mhz
57 8210b?avr?04/10 xmega d 6.3.3 peripheral clock - clk per the majority of peripherals a nd system modules use the perip heral clock. this includes the event system, interrupt controller and ram. this clock is always synchronous to the cpu clock but may run even if the cpu clock is turned off. 6.3.4 peripheral 2x/4x clocks clk per2 /clk per4 modules that can run at two or four times the cpu clock frequency can use the peripheral 2x and peripheral 4x clocks. 6.3.5 asynchronous clock - clk asy the asynchronous clock allows the real time counter (rtc) to be clocked directly from an external 32.768 khz crystal osc illator, or the 32 ti mes prescaled output from theinternal 32.768 khz oscillator or ulp oscillator. the dedi cated clock domain allo ws operation of this peripheral, even if the device is in a sleep mode where the rest of the clocks are stopped. 6.4 clock sources the clock sources are divided in two main grou ps: internal oscillators and external clock sources. most of the clock sources can be directly enabled and disabled from software, while others are automatically enabled or disabled dependent on current peripheral settings. after reset the device starts up running from the 2 mhz internal oscillator. the dflls and pll are turned off by default. 6.4.1 internal oscillators the internal osc illators do not require any external components to run. for details on character- istics and accuracy of the internal osc illators refer to th e device datasheet. 6.4.1.1 32 khz ultra low power oscillator this oscillator provides an ap proximate 32 khz clock. the 32 khz ultra low power (ulp) inter- nal oscillator is a very low powe r clock source, and it is not designed for high accuracy.the oscillator employs a built in prescaler prov iding both a 32 khz output and a 1 khz output. the oscillator is automatically enabl ed/disabled when used as clock source for any part of the device. this oscillator can be select ed as clock source for the rtc. 6.4.1.2 32.768 khz calibrated internal oscillator this rc oscillator provides an ap proximate 32.768 khz clock. a fa ctory-calibrated value is writ- ten to the 32.768 khz oscillator calibration regist er during reset to ensure that the oscillator is running within its specification. the calibration register can also be written from software for run- time calibration of the oscillator frequency. the oscillator employs a built in prescaler providing both a 32.768 khz output and a 1.024 khz output. 6.4.1.3 32 mhz run-time calib rated internal oscillator this rc oscillator provides an approximate 32 mhz cl ock. the oscillator employs a digital fre- quency locked loop (dfll) that can be enabled for automatic run-time calibration of the oscillator. a factory-calibrated value is written to the 32 mhz dfll calibration register during reset to ensure that the oscillator is running withi n its specification. the calibration register can also be written from software for manual run-time calibration of the oscillator.
58 8210b?avr?04/10 xmega d 6.4.1.4 2 mhz run-time calib rated internal oscillator this rc oscillator provides an approximate 2 mhz clock. the os cillator employs a digital fre- quency looked loop (dfll) that can be enabled for automatic run-time calibration of the oscillator. a factory-calibrated va lue is written to the 2 mhz dfll calibration register during reset to ensure that the oscillator is running withi n its specification. the calibration register can also be written from software for manual run-time calibration of the oscillator. 6.4.2 external clock sources the xtal1 and xtal2 pins can be us ed to drive an external oscilla tor, either a quartz crystal or a ceramic resonator. xtal1 can be used as input for an external clock signal. the tosc1 and tosc2 pins is dedicated for driv ing a 32.768 khz crystal oscillator. 6.4.2.1 0.4 - 16 mh z crystal oscillator this oscillator can operate in four different modes, optimized for different frequency ranges, all within 0.4 - 16 mhz. figure 6-2 shows a typical connection of a crystal oscillator or resonator. figure 6-2. crystal oscillator connection two capacitors, c1 and c2, may be added to match the required load capacitance for the con- nected crystal. 6.4.2.2 external clock input to drive the device from an external clock source, xtal1 must be driven as shown in figure 6- 3 on page 58 . in this mode, xtal2 can be used as a general i/o pin. figure 6-3. external clock drive configuration 6.4.2.3 32.768 khz crystal oscillator a 32.768 khz crystal oscillator can be connected between tosc1 and tosc2 by enabling a dedicated low frequency oscilla tor input circuit. a typical connection is shown in figure figure c1 c2 xtal2 xtal1 gnd general purpose i/o xtal2 xtal1 external clock signal
59 8210b?avr?04/10 xmega d 6-4 on page 59 . a low power mode with reduced voltage swing on tosc2 is available. this oscillator can be used as clock source for the system clock, rtc and as the dfll reference. figure 6-4. 32.768 khz crystal oscillator connection two capacitors, c1 and c2, may be added to match the required load capacitance for the con- nected crystal. 6.5 system clock se lection and prescalers all the calibrated internal oscilla tors, the external clock sources (xosc) and the pll output can be used as the system clock source. the system clock source is selectable from software, and can be changed during normal operation. built-in hardware protection prevents unsafe clock switching. it is not possible to se lect a non-stable or di sabled oscillator as cl ock source, or to dis- able the oscillator cu rrently used as system clock source. ea ch oscillator option has a status flag that can be read from software to check that the oscillator is ready. the system clock is fed into a prescaler block that can divide the clock signal by a factor from 1 to 2048 before it is routed to the cpu and peripherals. the prescaler settings can be changed from software during normal operation. the first stage, prescaler a, can divide by a factor of 1 to 512. then prescaler b and c can be individually configured to either pass the clock through or divide it by a factor of 1 to 4. the prescale r guarantees that derived clocks are always in phase, and that no glitches or intermediate frequencies occur when changing the prescaler setting. the prescaler settings are always updated in accordance to the rising edge of the slowest clock. figure 6-5. system clock selection and prescalers prescaler a divides the system clock and the resulting clock is the clk per4 . prescaler b and prescaler c can be enabled to di vide the clock speed further and enable peripheral modules to run at twice or four times the cpu clock frequency. if prescaler b and c are not used all the clocks will run at the same frequency as output from prescaler a. c1 c2 tosc2 tosc1 gnd prescaler a 1, 2, 4, ... , 512 prescaler b 1, 2, 4 prescaler c 1, 2 internal 2 mhz osc. internal 32.768 khz osc. internal 32 mhz osc. external oscillator or clock. clk cpu clock selection clk per clk sys clk per2 clk per4 internal pll.
60 8210b?avr?04/10 xmega d the system clock selection and prescaler registers are protected by the configuration change protection mechanism, employing a timed write procedure for changing the system clock and prescaler settings. for details refer to ?configuration change protection? on page 12 . 6.6 pll with 1-31x multiplication factor a built-in phase locked loop (pll) can be used to generate a high frequency system clock. the pll has a user selectable multiplication factor from 1 to 31. the output frequency, f out is given by the input frequency, f in multiplied with the mult iplication factor, pll_fac. for details on max- imum and minimum input and output frequency for the pll, refer to the device datasheet. four different reference clock sources can be chosen as input to the pll: ? 2 mhz internal oscillator ? 32 mhz internal oscillator divided by 4 ? 0.4 - 16 mhz crystal oscillator ? external clock to enable the pll the following procedure must be followed: 1 .enable clock reference source. 2 .set the multiplication factor and select the clock reference for the pll. 3 .wait until the clock reference source is stable. 4 .enable the pll. hardware ensures that the pll configuration cannot be changed when the pll is in use. the pll must be disabled before a new configuration can be written. it is not possible to use the pll before the selected clock source is stabile and the pll has locked. if using pll and dfll the active reference cannot be disabled. 6.7 dfll 2 mhz and dfll 32 mhz two built-in digital frequency locked loops (dflls ) can be used to improve the accuracy of the 2 mhz and 32 mhz internal oscillators. the dfll compares the oscillator frequency with a more accurate refere nce clock to do automatic run-time calibration of th e oscillator. the choices for the reference clock sources are: ? 32.768 khz calibrated internal oscillator ? 32.768 khz crystal oscillator connected to the tosc pins the dflls divide the reference clock by 32 to use a 1.024 khz reference. the reference clock is individually selected for each dfll as shown on figure 6-6 on page 61 . f out f in pll_fac ? =
61 8210b?avr?04/10 xmega d figure 6-6. figure 5-5. dfll reference clock selection when the dfll is enable d it will count each oscillator clock cycle, and for each reference clock edge, the counter value is compared to the fix ed ideal relationship between the reference clock and the 1.024 khz referenc e frequency. if the internal oscillato r runs too fast or too slow, the dfll will decrement or increment the corresponding dfll calibra tion register va lue by one to adjust the oscillator frequency s lightly. when the dfll is enabled the dfll calibration register cannot be written from software. the ideal counter value representing the number of oscillator clock cycles for each reference clock cycle is loaded to the dfll oscillator comp are register during rese t. the register can also be written from software to change the freq uency the internal osc illator is calibrated to. the dfll will stop when entering a sleep-mode w here the oscillators are stopped. after wake- up the dfll will continue with the calibration value found befo re entering sleep. for the dfll calibration register to be reloaded with the default value it has after reset, the dfll must dis- abled before entering sleep and enabled the again after leaving sleep. the active reference cannot be disabled when the dfll is enabled. when the dfll is disabled the dfll calibration register can be written from software for man- ual run-time calibrati on of the oscillator. for details on internal oscillator accuracy when the dfll is enabled, refer to the device datasheet. 6.8 external clock source failure monitor to handle external clock source failures, there is a built-in moni tor circuit monitoring the oscilla- tor or clock used to derive the xosc clock. the external clock source failure monitor is disabled by default, and it must be enabled from software before it can be used. if an external tosc1 tosc2 32.768 khz crystal osc. 32.768 khz int. osc. 2 mhz int. osc. 32 mhz int. osc. dfll dfll
62 8210b?avr?04/10 xmega d clock or oscillator is used to derive the system clock (i.e clock reference for the pll when this is used as the active system clock) and an cl ock or oscillator fails (stops), the device will: ? switch to the 2 mhz internal oscillator, in dependently of any clock system lock setting. ? reset the oscillator control re gister and system clock select ion register to their default values. ? set the external clock source failure detection interrupt flag. ? issue a non-maskable interrupt (nmi). if the external oscillator fails wh en it is not used as the system clock source, the external oscil- lator is automatically disabl ed while the system clock will co ntinue to op erate normally. if the external clock is below 32 khz then the failure monitor mechanism should not be enabled in order to avoid unintentional fail detection. when the failure monitor is enabled, it cannot be disabled until next reset. the failure monitor is automatically disabled in all sleep modes where the external clock or oscil- lator is stopped. during wake-up from sleep it is automatically enabled again. the external clock source failure monitor setting is protected by the configuration change pro- tection mechanism, employing a timed write procedure for changing the system clock and prescaler settings. for details refer to ?configuration change protection? on page 12 .
63 8210b?avr?04/10 xmega d 6.9 register descr iption - clock 6.9.1 ctrl - system clock control register ? bit 7:3 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 2:0 - sclksel[2:0]: system clock selection sclksel is used to select the so urce for the system clock. see table 6-1 for the different selections. changing the system clock source wi ll take 2 clock cycles on the old clock source and 2 clock cycles on the new clock source. t hese bits are protected by the configuration change protection mechanism, for details refer to ?configuration change protection? on page 12 . sclksel cannot be changed if the new source is not stable. 6.9.2 psctrl - system clock prescaler register ? bit 7 - reserved this bit is reserved and will a lways be read as zero. for compat ibility with future devices, always write this bit to zero when this register is written. bit 76543210 +0x00 ? ? ? ? ? sclksel[2:0] ctrl read/writerrrrrr/wr/wr/w initial value00000000 table 6-1. system clock selection sclksel[2:0] group configuration description 000 rc2mhz 2 mhz internal rc oscillator 001 rc32mhz 32 mhz internal rc oscillator 010 rc32khz 32.768 khz internal rc oscillator 011 xosc external oscillator or clock 100 pll phase locked loop 101 - reserved 110 - reserved 111 - reserved bit 76543210 +0x01 ? psadiv[4:0] psbcdiv psctrl read/write r r/w r/w r/w r/w r/w r/w r/w initial value00000000
64 8210b?avr?04/10 xmega d ? bit 6:2 - psadiv[4:0]: prescaler a division factor these bits define the division ratio of the clock prescaler a according to table 6-2 . these bits can be written run-time to change the clock frequency of the clk per4 clock relative to the system clock, clk sys . ? bit 1:0 - psbcdiv: prescaler b and c division factor these bits define the division ratio of the clock prescaler b and c according to table 6-3 . pres- caler b will set the clock frequency for the clk per2 clock relative to the clk per4 . prescaler c will set the clock frequency for the clk per and clk cpu clocks relative to the clk per2 clock. refer to fig- ure 6-5 on page 59 fore more details. table 6-2. prescaler a division factor psadiv[4:0] group configuration description 00000 1 no division 00001 2 divide by 2 00011 4 divide by 4 00101 8 divide by 8 00111 16 divide by 16 01001 32 divide by 32 01011 64 divide by 64 01101 128 divide by 128 01111 256 divide by 256 10001 512 divide by 512 10101 reserved 10111 reserved 11001 reserved 11011 reserved 11101 reserved 11111 reserved table 6-3. prescaler b and c division factor psbcdiv[1:0] group configuration prescaler b division prescaler c division 00 1_1 no division no division 01 1_2 no division divide by 2 10 4_1 divide by 4 no division 11 2_2 divide by 2 divide by 2
65 8210b?avr?04/10 xmega d 6.9.3 lock - clock system lock register ? bit 7:1 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 0 - lock: clock system lock when the lock bit is written to one the ctrl and psctrl registers cannot be changed, and the system clock selection and prescaler settings is protected against all further updates until after the next reset. this bits are protected by the configuration change protection mechanism, for details refer to ?configuration change protection? on page 12 . the lock bit will only be cleared by a system reset. 6.9.4 rtcctrl - rt c control register ? bit 7:4 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 3:1 - rtcsrc[2:0]: clock source these bits select the clock source for the real time counter according to table 6-4 . bit 76543210 +0x02 ? ? ? ? ? ? ? lock lock read/writerrrrrrrr/w initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x03 ? ? ? ? rtcsrc[2:0] rtcen rtcctrl read/writerrrrr/wr/wr/wr/w initial value00000000 table 6-4. rtc clock source rtcsrc[2:0] group configuration description 000 ulp 1 khz from internal 32 khz ulp 001 tosc 1.024 khz from 32.768 khz crystal oscillator on tosc 010 rcosc 1.024 khz from internal 32.768 khz rc oscillator 011 - reserved 100 - reserved 101 tosc32 32.768 khz from 32.768 khz crystal oscillator on tosc 110 - reserved 111 - reserved
66 8210b?avr?04/10 xmega d ? bit 0 - rtcen: rtc clock source enable setting the rtcen bit enables the selected clock source for the real time counter. 6.10 register descr iption - oscillator 6.10.1 ctrl - oscillator control register ? bit 7:5 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 4 - pllen: pll enable setting this bit enables the pll. before the pll is enabled, it should be configured with the desired multiplication factor and input source. see ?status - oscillator status register? on page 67. ? bit 3 - xoscen: external oscillator enable setting this bit enables the selected external clock source, refer to ?xoscctrl - xosc control register? on page 67 for details on how to select and enable an external clock source. the external clock source should be allowed time to become stable before it is selected as source for the system clock. see ?status - oscillator status register? on page 67. ? bit 2 - rc32ken: 32.768 khz internal rc oscillator enable setting this bit enables the 32.768 khz internal rc oscillator. the oscillator must be stable before it is selected as source for the system clock. see ?status - oscillator status register? on page 67. ? bit 1- rc32men: 32 mhz internal rc oscillator enable setting this bit will enable the 32 mhz internal rc oscillator. the oscillato rs should be allowed time to become stable before wither is selected as source for the system clock. see ?status - oscillator status register? on page 67. ? bit 0 - rc2men: 2 mhz internal rc oscillator enable setting this bit enables the 2mhz internal rc oscillator. the osc illator should be allowed time to become stable before wither is selected as source for the system clock. see ?status - oscil- lator status register? on page 67. by default the 2 mhz internal rc oscilla tor is enabled and this bit is set. bit 76543210 +0x00 ? ? ? pllen xoscen rc32ken rc32men rc2men ctrl read/write r r r r/w r/w r/w r/w r/w initial value00000001
67 8210b?avr?04/10 xmega d 6.10.2 status - oscillator status register ? bit 7:5 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 4 - pllrdy: pll ready the pllrdy flag is set when the pll has lo cked on selected frequency and ready to be used as he system clock source. ? bit 3 - xoscrdy: external clock source ready the xoscrdy flag is set when the external clock source is stable and ready to be used as the system clock source. ? bit 2 - rc32krdy: 32.768 khz internal rc oscillator ready the rc32krdy flag is set when the 32.768 khz in ternal rc oscillator is stable and ready to be used as the system clock source. ? bit 1 - rc32mrdy: 32 mhz internal rc oscillator ready the r32mrfy flag is set when the 32 mhz inter nal rc oscillator is stable and ready to be used as the system clock source. ? bit 0 - rc2mrdy: 2 mhz internal rc oscillator ready the rc2mrdy flag is set when t he 2 mhz internal rc oscillato r is stable and is ready to be used as the system clock source. 6.10.3 xoscctrl - xo sc control register ? bit 7:6 - frqrange[1:0]: crystal oscillator frequency range select these bits select the frequen cy range for the connected cr ystal oscillator according to table 6-5 on page 68 . bit 765 4 3 2 1 0 +0x01 ? ? ? pllrdy xoscrdy rc32krdy r32mrdy rc2mrdy status read/write r r r r r r r r initial value 0 0 0 0 0 0 0 0 bit 7 6 5 43210 +0x02 frqrange[1:0] x32klpm ? xoscsel[3:0] xoscctrl read/write r/w r/w r/w r r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
68 8210b?avr?04/10 xmega d ? bit 5 - x32klpm: crystal oscillator 32.768 khz low power mode setting this bit enables low pow er mode for the 32.7 68 khz crystal oscilla tor. this will reduce the swing on the tosc2 pin to save power. ? bit 4 - reserved this bit is reserved and will a lways be read as zero. for compat ibility with future devices, always write this bit to zero when this register is written. ? bit 3:0 - xoscsel[3:0]: crystal oscillator selection these bits select the type and start-up time for the crystal or resonator that is connected to the xtal or tosc pins. it is impossible to change this configuration when xoscen in ctrl is set. see table 6-6 for crystal selections.. notes: 1. this option should only be used when frequ ency stability at start-up is not important for the application. the option is not suitable for crystals. 2. this option is intended for use with cerami c resonators and will ensure frequency stability at start-up. it can also be used when the frequen cy stability at start-up is not important for the application. 6.10.4 xoscfail - xosc failure detection register table 6-5. oscillator frequency range selection frqrange[1:0] group config uration frequency range recommended range for capacitors c1 and c2 (pf) 00 04to2 0.4 mhz - 2 mhz 100 01 2to9 2 mhz - 9 mhz 15 10 9to12 9 mhz - 12 mhz 15 11 12to16 12 mhz - 16 mhz 10 table 6-6. external oscillator selection and startup time xoscsel[3:0] group configuration selected clock source start-up time 0000 extclk external clock 6 clk 0010 32khz 32.768 khz tosc 16k clk 0011 xtal_256clk (1) 0.4 - 16 mhz xtal 256 clk 0111 xtal_1kclk (2) 0.4 - 16 mhz xtal 1k clk 1011 xtal_16kclk 0.4 - 16 mhz xtal 16k clk bit 765432 1 0 +0x03 ? ? ? ? ? ? xoscfdif xoscfden xoscfail read/writerrrrrrr/wr/w initial value000000 0 0
69 8210b?avr?04/10 xmega d ? bit 7:2 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 1 - xoscfdif: failure detection interrupt flag if the external clock source oscillator failure monitor is enabled, the xoscfdif is set when a failure is detected. writing logic one to this lo cation will clear xoscfdif. note that having this flag set will not stop the fail monitor circuit to req uest a new interrupt if th e external clock sources are re-enabled and a new failure occurs. ? bit 0 - xoscfden: failure detection enable setting this bit will enable the failure detection monitor, and a non-maskable interrupt will be issued when the xoscfdif is set. this bit is protected by the configuratio n change protection mechanism, refer to ?configuration change protection? on page 12 for details. once enabled, the failure detection will only be dis- abled by a reset. 6.10.5 rc32kcal - 32.768 khz oscillator calibration register ? bit 7:0 - rc32kcal[7:0]: 32.768 khz internal oscillator calibration register this register is used to calibra te the internal 32.768 khz oscilla tor. a factory-ca librated value is loaded from the signature row of the device and written to this register during reset, giving an oscillator frequency close to 32.768 khz. the register can also be written from software to cali- brate the oscillator frequency during normal operation. 6.10.6 pllctrl - pll control register ? bit 7:6 - pllsrc[1:0]: clock source the pllsrc bits select the input source for the pll according to table 6-7 on page 70 . bit 76543210 +0x04 rc32kcal[7:0] rc32kcal read/write r/w r/w r/w r/w r/w r/w r/w r/w initial valuexxxxxxxx bit 76543210 +0x05 pllsrc[1:0] ? pllfac[4:0] pllctrl read/write r/w r/w r r/w r/w r/w r/w r/w initial value00000000
70 8210b?avr?04/10 xmega d notes: 1. 32 khz tosc cannot be selected as source for the pll. an external clock must be minimum 0.4 mhz to be used as source clock. ? bit 5 - reserved this bit is reserved and will a lways be read as zero. for compat ibility with future devices, always write this bit to zero when this register is written. ? bit 4:0 - pllfac[4:0]: multiplication factor the pllfac bits set the multiplication factor for the pll. the multiplication factor can be in the range from 1x to 31x. 6.10.7 dfllctrl - dfll control register ? bit 7:2 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 1 - rc32mcref: 32 mhz calibration reference this bit is used to select the calibration source for the 32 mhz dfll. by default this bit is zero and the 32.768 khz internal rc osc illator is selected. if this bit is set to one the 32.768 khz crys- tal oscillator connected to tosc selected as re ference. the xoscen bit in the ctrl register must be set to enable the exte rnal oscillator, and the xosclsel bits in the xoscctrl register must be set to 32.768 khz tosc when this clock source is selected as the the 32 mhz dfll reference. ? bit 0 - rc2mcref: 2 mhz calibration reference this bit is used to select the calibration source for the 2 mhz dfll. by default this bit is zero and the 32.768 khz internal rc oscillator is selected. if this bit is set to one the 32.768 khz crystal oscillator on tosc is selected as reference. the xoscen bit in th e ctrl register must be set to enable the external oscillator, and the xosclsel bits in the xoscctrl register must be set to 32.768 khz tosc when this clock source is selected as the the 2 mhz dfll reference. table 6-7. pll clock source clksrc[1:0] group configuration pll input source 00 rc2m 2 mhz internal rc oscillator 01 - reserved 10 rc32m 32 mhz internal rc oscillator 11 xosc external clock source (1) bit 765432 1 0 +0x06 ? ? ? ? ? ? r32mcref rc2mcref dfllctrl read/write r r r r r r r/w r/w initial value 0 0 0 0 0 0 0 0
71 8210b?avr?04/10 xmega d 6.11 register descrip tion - dfll32m/dfll2m 6.11.1 ctrl - dfll control register ? bit 7:1 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 0 - enable: dfll enable setting this bit enables the dfll and auto -calibration of the internal oscillator 6.11.2 cala - calibration register a cala and calb register holds the 13 bit dfll calibration value that is used for automatic run- time calibration the internal oscillator. when the dfll is disabled, the calibration registers can be written by software for manual run-time calib ration of the oscillator. the oscillators will be cal- ibrated according to the calibration value in these registers also when the dfll is disabled. ? bit 7:0 - call[7:0]: dfll calibration bits these bits hold the 7 lea st significant bits (lsb) of the calib ration value for the oscillator. after reset call is set to its middle value, and duri ng automatic runtime calibration of the oscillator these bits are use to change th e oscillator frequency. the bits are controlled by the dfll when the dfll is enabled. 6.11.3 calb - calibration register b ? bit 7:5 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. bit 76543210 +0x00 ? ? ? ? ? ? ? enable ctrl read/writerrrrrrrr/w initial value00000000 bit 76543210 +0x02 call[7:0] cala read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value01000000 bit 76543210 +0x03 ? ? ? calh[12:8] calb read/write r r r r/w r/w r/w r/w r/w initial value 0 0 0 x x x x x
72 8210b?avr?04/10 xmega d ? bit 4:0 - calh[12:8]: dfll calibration bits these bits hold the 6 most signif icant bits (msb) of th e calibration value for the oscillator. a fac- tory-calibrated value is loaded from the signature row of the device and written to this register during reset, giving an oscilla tor frequency approximate to the nominal frequency for the oscilla- tor. these bits are not changed during auto matic runtime calibrati on of the oscillator. 6.11.4 comp0 - oscillator compare register 0 comp0, comp1 and comp2 represent the register value comp that hold the oscillator com- pare value. during reset comp is loaded with the default value representing the ideal relationship between oscillator frequency and the 1.024 khz reference clock. it is possible to write these bits from software, a nd then enable th e oscillator to tune to a frequency different than its nominal frequency. these bits can only be written when the dfll is disabled. ? bit 7:0 - comp[7:0] these bits are the low byte of the comp register. 6.11.5 comp1 - oscillator compare register 1 ? bit 7:0 - comp[15:8] these bits are the middle byte of the comp register. 6.11.6 comp2 - oscillator compare register 2 ? bit 7:4 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 3:0 - comp[19:16] these bits are the highest bits of the comp register. bit 76543210 +0x04 comp[7:0] comp0 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x05 comp[15:8] comp1 read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x06 ? ? ? ? comp[19:16] comp2 read/write r r r r r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
73 8210b?avr?04/10 xmega d 6.12 register summary - clock 6.13 register summary - oscillator 6.14 register summ ary - dfll32m/dfll2m 6.15 crystal oscillator fail ure interrupt vector summary address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 ctrl ? ? ? ? ? sclksel[2:0] 63 +0x01 psctrl ? psadiv[4:0] psbcdiv[1:0] 63 +0x02 lock ? ? ? ? ? ? ?lock65 +0x03 rtcctrl ? ? ? ? rtcsrc[2:0] rtcen 65 +0x04 reserved ? ? ? ? ? ? ? ? +0x05 reserved ? ? ? ? ? ? ? ? +0x06 reserved ? ? ? ? ? ? ? ? +0x07 reserved ? ? ? ? ? ? ? ? address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 ctrl ? ? ? pllen xoscen rc32ken r32men rc2men 66 +0x01 status ? ? ? pllrdy xoscrdy rc32krdy r32mrdy rc2mrdy 66 +0x02 xoscctrl frqrange[1:0] x32klpm - xoscsel[3:0] 67 +0x03 xoscfail ? ? ? ? ? ? xoscfdif xoscfden 68 +0x04 rc32kcal rc32kcal[7:0] 69 +0x05 pllctrl pllsrc[1:0] - pllfac[4:0] 69 +0x06 dfllctrl ? ? ? ? ? ? r32mcref rc2mcref 70 +0x07 reserved ? ? ? ? ? ? ? ? +0x08 reserved ? ? ? ? ? ? ? ? +0x09 reserved ? ? ? ? ? ? ? ? +0x0a reserved ? ? ? ? ? ? ? ? +0x0b reserved ? ? ? ? ? ? ? ? +0x0c reserved ? ? ? ? ? ? ? ? +0x0d reserved ? ? ? ? ? ? ? ? +0x0e reserved ? ? ? ? ? ? ? ? +0x0f reserved ? ? ? ? ? ? ? ? address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 ctrl ? ? ? ? ? ? ?enable71 +0x01 reserved ? ? ? ? ? ? ? ? +0x02 cala call[7:0] 71 +0x03 calb ? ? ? calh[12:8] 71 +0x04 comp0 comp[7:0] 71 +0x05 comp1 comp[15:8] 72 +0x06 comp2 ? ? ? ? comp[19:16] 72 +0x07 reserved ? ? ? ? ? ? ? ? table 6-8. crystal oscillator failure inte rrupt vector and its word offset address crystal osc illator failure interrupt base offset source interr upt description 0x00 oscf_vect crystal oscillator failure interrupt vector (nmi)
74 8210b?avr?04/10 xmega d 7. power management and sleep 7.1 features ? 5 sleep modes ?idle ? power-down ?power-save ?standby ? extended standby ? power reduction register to disa ble clock to unused peripherals 7.2 overview xmega provides various sleep modes and software controlled clock gating in order to tailor power consumption to the application's requirement. sleep modes enables the microcontroller to shut down unused modules to save power. when the device enters sleep mode, program exe- cution is stopped and interrupts or reset is used to wake the device again. the individual clock to unused peripherals can be stopped during normal oper ation or in sleep, enabling a much more fine tuned power management than sleep modes alone. 7.3 sleep modes sleep modes are used to shut down modules and clock domains in the microcontroller in order to save power. xmega ha s five different sleep modes. a de dicated sleep instruction (sleep) is available to enter sleep. before executing sleep, the selected sleep mode to enter must be configured. the available interrupt wake-up sources is dependent on the selected sleep mode. when an enabled interrupt occurs the device will wake up and execute t he interrupt service rou- tine before continuing normal program execution from the first instruction after the sleep instruction. if other higher priority interrupts are pending when the wake-up occurs, their interrupt service routines will be executed a ccording to their priority before the interrupt serv ice routine for the wake-up interrupt is executed . after wake-up th e cpu is halted for four cycles before execu- tion starts.
75 8210b?avr?04/10 xmega d table 7-1 on page 75 shows the different sleep modes and the active clock domains, oscillators and wake-up sources. the wake-up time for the device is dependent on the sleep mode and the main clock source. the start-up time for the system clock source must be added to the wake-up time for sleep modes where the clock source is stopped. for deta ils on the start-up time for the different oscil- lators options refer to ?system clock and clock options? on page 55 . the content of the register file, sram and registers are kept during sleep. if a reset occurs during sleep, the device will reset, star t up and execute from the reset vector. 7.3.1 idle mode in idle mode the cpu and non-volatile memory are stopped, (note that any active programming will be completed) but all peri pherals includi ng the interrupt controlle r and event system are kept running. any inte rrupt request in terrupts will wake the device. 7.3.2 power-down mode in power-down mode all system clock sources, including the real time counter clock source are stopped. this allows operation of asynchronous modules only. the only interrupts that can wake up the mcu are the two wire interface address match interrupts, and asynchronous port interrupts. 7.3.3 power-save mode power-save mode is identical to power-down, with one exception: if the real time counter (rtc) is enabled, it will keep running during sl eep and the device can also wake up from either rtc overflow or compare match interrupt. table 7-1. active clock domains an d wake-up sources in the different sleep modes. active clock domain oscillators wake-up sources sleep modes cpu clock peripheral clock rtc clock system clock source rtc clock source asynchronous port interrupts twi address match interrupts real time clock interrupts all interrupts idle x x x x xxxx power-down x x power-save x x x x x standby x x x extended standby x x x x x x
76 8210b?avr?04/10 xmega d 7.3.4 standby mode standby mode is identical to power-down with the exception that the enabled system clock sources are kept running, while the cpu, periph eral and rtc clocks are stopped. this reduces the wake-up time. 7.3.5 extended standby mode extended standby mode is identical to power-save mode with the exception that the enabled system clock sources are kept ru nning while the cpu and periph eral clocks are stopped. this reduces the wake-up time. 7.4 power reduction registers the power reduction (pr) registers provides a method to stop the clock to individual peripher- als. when this is done the current state of the peripheral is frozen and the associated i/o registers cannot be r ead or written. resource s used by the peripheral will remain occupied; hence the peripheral should in most cases be disabled before stopping the clock. enabling the clock to a peripheral again, puts the peripheral in the same state as before it was stopped. this can be used in idle mode and active mode to reduce the overall power consumption signifi- cantly. in all other sleep modes, the peripheral clock is already stopped. not all devices have all the peripherals associated with a bit in the power reduction registers. setting a power reduction bit for a peripheral that is not availabl e will have no effect. 7.5 register description ? sleep 7.5.1 ctrl- sleep control register ? bit 7:4 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 3:1 - smode[2:0]: sleep mode selection these bits select sleep modes according to table 7-2 on page 76 . bit 76543210 +0x00 ? ? ? ? smode[2:0] sen ctrl read/writerrrrr/wr/wr/wr/w initial value00000000 table 7-2. sleep mode smode[2:0] sen group configuration description xxx 0 off no sleep mode enabled 000 1 idle idle mode 001 1 - reserved 010 1 pdown power-down mode 011 1 psave power-save mode 100 1 - reserved
77 8210b?avr?04/10 xmega d ? bit 1 - sen: sleep enable this bit must be set to make the mcu enter the selected sleep mode when the sleep instruc- tion is executed. to avoid unintentional entering of sleep modes, it is recommended to write sen just before executing the sl eep instruction, and clearing it immediately after waking up. 7.6 register descripti on ? power reduction 7.6.1 prgen - general power reduction register ? bit 7:3 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 2 - rtc: real-time counter setting this stops the clock to the real time counter. when the bit is cleared the peripheral should be reinitialized to ensure proper operation. ? bit 1 - evsys: event system setting this stops the clock to t he event system. when the bit is cleared the module will continue like before the shutdown. ? bit 0 - reserved this bit is reserved and will a lways be read as zero. for compat ibility with future devices, always write this bit to zero when this register is written. 7.6.2 prpa/b - power redu ction port a/b register note: disabling of analog modules stops the clock to the analog blocks themselves and not only the interfaces. 101 1 - reserved 110 1 stdby standby mode 111 1 estdby extended standby mode table 7-2. sleep mode smode[2:0] sen group configuration description bit 76543210 +0x00 ? ? ? ? ? rtc evsys ?prgen read/write r r r r r r/w r/w r initial value00000000 bit 765432 1 0 +0x01/+0x02 ? ? ? ? ? ? adc ac prpa read/writerrrrrrr/wr/w initial value000000 0 0
78 8210b?avr?04/10 xmega d ? bit 7:2 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 1 - adc: power reduction adc setting this bit stops the clock to the adc. the adc should be disabled before shut down. ? bit 0 - ac: power reduction analog comparator setting this bit stops the clock to the analog comparator. the ac should be disabled before shut down. 7.6.3 prpc/d/e/f - power reduction port c/d/e/f register ? bit 7 - reserved this bit is reserved and will a lways be read as zero. for compat ibility with future devices, always write this bit to zero when this register is written. ? bit 6 - twi: two-wire interface setting this bit stops the clock to the two-wire interface. when the bit is cleared the peripheral should be reinitialized to ensure proper operation. ? bit 5 - reserved this bit is reserved and will a lways be read as zero. for compat ibility with future devices, always write this bit to zero when this register is written. ?bit 4 - usart0 setting this bit stops the clock to the usart0. w hen the bit is cleared the peripheral should be reinitialized to ensure proper operation. ? bit 3 - spi: serial peripheral interface setting this bit stops the clock to the spi. when the bit is cleared the peripheral should be reini- tialized to ensure proper operation. ? bit 2 - hires: hi-resolution extension setting this bit stops the clock to the hi-resolution extension for the timer/counters. when the bit is cleared the peripheral should be reinitialized to ensure proper operation. ? bit 1 - tc1: timer/counter 1 setting this bit stops the clock to the timer/coun ter 1. when the bit is cleared the peripheral will continue like before the shut down. bit 76543210 ?twi ? usart0 spi hires tc1 tc0 prpc/d/e/f read/write r r/w r r/w r/w r/w r/w r/w initial value00000000
79 8210b?avr?04/10 xmega d ? bit 0 - tc0: timer/counter 0 setting this bit stops the clock to the timer/coun ter 0. when the bit is cleared the peripheral will continue like before the shut down. 7.7 register summary - sleep 7.8 register summar y - power reduction address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 ctrl ? ? ? ?smode[2:0]sen76 +0x01 reserved ? ? ? ? ? ? ? ? +0x02 reserved ? ? ? ? ? ? ? ? +0x03 reserved ? ? ? ? ? ? ? ? +0x04 reserved ? ? ? ? ? ? ? ? +0x05 reserved ? ? ? ? ? ? ? ? +0x06 reserved ? ? ? ? ? ? ? ? +0x07 reserved ? ? ? ? ? ? ? ? address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 prgen ? ? ? ? ? rtc evsys ?77 +0x01 prpa ? ? ? ? ? ?adcac 77 +0x02 reserved ? ? ? ? ? ? ? ? +0x03 prpc ?twi ? usart0 spi hires tc1 tc0 78 +0x04 prpd ? ? ?usart0spi ? ? tc0 78 +0x05 prpe ? ? ?usart0 ? ? ?tc078 +0x06 prpf ? ? ?usart0 ? ? ?tc078 +0x07 reserved ? ? ? ? ? ? ? ?
80 8210b?avr?04/10 xmega d 8. reset system 8.1 features ? power-on reset source ? brown-out reset source ? software reset source ? external reset source ? watchdog reset source ? program and debug interface reset source 8.2 overview the reset system will issue a system reset and set t he device to its initial state if a reset source goes active. all io registers will be set to their initial value, and the program counter is reset to the reset vector location. the reset controller is asynchronous, hence no running clock is required to reset the device. xmega has seven different reset sources. if mo re than one reset source is active, the device will be kept in reset until all rese t sources have released their re set. after reset is released from all reset sources, the default oscillator is started and calibrated before the internal reset is released and the device starts running. the reset system has a status register with indi vidual flags for each re set source. the status register is cleared at power-on reset, hence this register will show which source(s) that has issued a reset since the last power-on. a software reset feature makes it possible to issue a sys- tem reset from the user software. an overview of the reset system is shown in figure 8-1 on page 81 .
81 8210b?avr?04/10 xmega d figure 8-1. reset system overview reset delay counter oscillator startup oscillator calibration power - on detection reset brown - out detection reset external reset watchdog reset program and debug interface reset software reset r s reset status register internal reset timeout counter reset
82 8210b?avr?04/10 xmega d 8.3 reset sequence reset request from any reset source immediately reset the device, and keep it in reset as long as the request is active. when all reset requests are released, the device will go through three stages before the internal reset is released and the device starts running. ? reset counter delay ? oscillator startup ? oscillator calibration if one of the reset request occur during this, the reset se quence will start over again. 8.3.1 reset counter delay the reset counter delay is the programmable period from all reset requests are released and until the reset counter times out and releases reset. the reset counter delay is timed from the 1 khz output of the ultra low power (ulp) internal oscillator, and the number of cycles before the timeout is set by the startuptime fuse bits. the selectable delays are shown in table 8- 1 . 8.3.2 oscillator startup after the reset counter delay, the default clock is started. this is the 2 mhz internal rc oscilla- tor, and this uses 6 clock cycles to startup and stabilize. 8.3.3 oscillator calibration after the default oscillator has st abilized, oscillator calibration va lues are loaded from non-vola- tile memory into the oscillato r calibration registers. loadin g the calibration values takes 24 clock cycles on the internal 2 mhz oscillator. the 2 mhz, 32 mhz and 32.768 khz internal rc oscillators are calibrated. when this is done the device w ill enter active mo de and program exe- cution will begin. 8.4 reset sources 8.4.1 power-on reset a power-on detection circuit will give a po wer-on reset (por) w hen supply voltage (v cc ) is applied to the device and the v cc slope is increasing in the power-on slope range (v posr ). power-on reset is released when the v cc stops rising or when the v cc level has reached the power-on threshold voltage (v pot ) level. when v cc is falling, the por will issue a reset when th e vpot level is reach ed. the vpot level is lower than the minimum operating voltage for the device, and is only used for power-off function- table 8-1. reset counter delay sut[1:0] number of 1 khz ulp oscillator clock cycles 00 64 01 4 10 reserved 11 0
83 8210b?avr?04/10 xmega d ality and not to ensure safe operation. the brown-out detection (bod) must be enabled to ensure safe operation and detect if v cc voltage drops below minimum operating voltage. only the power-on reset flag w ill be set after power-on reset. the brown-out reset flag is not set even though the bod circuit is used. figure 8-2. power-on reset (por) figure 8-3. increasing v cc slope in the power-on slope range. for characterization data on the v pot level for rising and falling v cc , and v posr slope consult the device datasheet. note that the power-on detection circuit is not designed to detect drops in the v cc voltage. brown-out detection must be enabled to detect falling v cc voltage, even if the v cc level falls below the v pot level. cc v timeout i n ter n al reset t tout v bot v pot v t v pot v posr,max v cc v cc dv dt
84 8210b?avr?04/10 xmega d 8.4.2 brown-out detection the brown-out detection (bod) circuit monitors that the v cc level is kept above a configurable trigger level, v bot . when the bod is enabled, a bod reset will be given if the v cc level falls bel- low the trigger level for a minimum time, t bod . the reset is kept active until the v cc level rises above the trigger level again. figure 8-4. brown-out detection reset. for characterization data on t bod consult the device datasheet. the trigger level is determined by a programmable bo dlevel setting, see table 8-2 . note: 1. the values here are nominal values only. for typical, maximum and minimum numbers consult the device datasheet. the bod circuit has 3 modes of operation: ? disabled: in this mode there is no monitoring of the v cc level, and hence it is only recommended for applications where the power supply is stable. ? enabled: in this mode the v cc level is continuously monitored, and a drop in v cc below v bot for at least t bod will give a brown-out reset. table 8-2. programmable bodlevel setting bodlevel[2:0] (1) v bot unit 111 1.6 v 110 1.8 101 2.0 100 2.2 011 2.4 010 2.6 001 2.8 000 3.0 v cc time-out internal reset v bot- v bot+ t tout t bod
85 8210b?avr?04/10 xmega d ? sampled: in this mode the bod circuit will sample the vcc level with a period identical to the 1 khz output from the ultra low power (ulp) oscillator. between each sample the bod is turned off. this mode will reduce the power co nsumption compared to the enabled mode, but a fall in the v cc level between 2 positive edges of the 1 khz ulp output will not be detected. if a brown-out is detected in this mode, the bod circuit is set in enabled mode to ensure that the device is kept in reset until v cc is above v bot again. the bodact fuse determines the bod setting for active mode and idle mode, while the bodds fuse determines the brown-out detection setting for all sleep modes except idle mode. 8.4.3 external reset the external reset circuit is co nnected to the external reset pin. the external reset will trigger when the reset pin is driven below the reset pin threshold voltage, v rst , for longer than the minimum pulse period t ext . the reset will be held as long as the pin is kept low. the reset pin includes an internal pull-up resistor. figure 8-5. external reset characteristics. for characterization data on v rst and t ext and pull-up resistor values consult the device datasheet. 8.4.4 watchdog reset the watchdog timer (wdt) is a system function for monitoring correct program operation. if the wdt is not reset from the software within a pr ogrammable timout period, a watchdog reset will be given. the watchdog reset is active for 1-2 clock cycles on the 2 mhz internal rc oscillator. table 8-3. bod setting fuse decoding bodact[1:0]/ bodds[1:0] mode 00 reserved 01 sampled 10 enabled 11 disabled cc t ext
86 8210b?avr?04/10 xmega d figure 8-6. watchdog reset. for information on configuration and use of the wdt, refer to the ?wdt ? watchdog timer? on page 89 . 8.4.5 software reset the software reset makes it possible to issue a system reset from software by writing to the software reset bit in the reset c ontrol register.the reset will be issued within 1-2 system clock cpu cycles after writing the bit. it is not possible to execute any instruction from a software reset is requested and until it is issued. figure 8-7. software reset 8.4.6 program and debug interface reset the program and debug interface reset contains a separate reset source that is used to reset the device during external programming and debuggin g. this reset source is only accessible from debuggers and programmers. 1-2 2mhz cc cycles software cc 1-2 2mhz cycle
87 8210b?avr?04/10 xmega d 8.5 register description 8.5.1 status - reset status register ? bit 7:6 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 5 - srf: software reset flag this flag is set if a software re set occurs. the flag will be cleared by a power-on rese t or by writ- ing a one to the bit location. ? bit 4 - pdirf: program and debug interface reset flag this flag is set if a programming interface reset occurs. the flag will be cleared by a power-on reset or by writing a one to the bit location. ? bit 3 - wdrf: watchdog reset flag this flag is set if a watchdog reset occurs. the flag will be cleared by a power-on reset or by writing a one to the bit location. ? bit 2 - borf: brown out reset flag this flag is set if a brown out reset occurs. the flag will be cleared by a power-on reset or by writing a one to the bit location. ? bit 1 - extrf: external reset flag this flag is set if an external reset occurs. the fl ag will be cleared by a power-on reset or by writ- ing a one to the bit location. ? bit 0 - porf: power on reset flag this flag is set if a power-on reset occurs. wr iting a one to the flag will clear the bit location. 8.5.2 ctrl - reset control register ? bit 7:1 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. bit 76543210 +0x00 ? ? srf pdirf wdrf borf extrf porf status read/write r r r/w r/w r/w r/w r/w r/w initial value???????? bit 76543210 +0x01 ? ? ? ? ? ? ?swrstctrl read/writerrrrrrrr/w initial value00000000
88 8210b?avr?04/10 xmega d ? bit 0 - swrst: software reset when this bit is set, a software reset will occur. the bit is cleared when a reset is issued. this bit is protected by the configuration change protection, for details refer to ?configuration change protection? on page 12 . 8.6 register summary address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 status ? ? srf pdirf wdrf borf extrf porf 87 +0x01 ctrl ? ? ? ? ? ? ?swrst87
89 8210b?avr?04/10 xmega d 9. wdt ? watchdog timer 9.1 features ? 11 selectable timeout period, from 8 ms to 8s ? two operation modes ? standard mode ? window mode ? runs from 1 khz ultra low power clock reference ? configuration lock 9.2 overview the watchdog timer (wdt) is a system function for monitoring correct program operation, mak- ing it possible to recover from error situations, for instance run-away code. the wdt is a timer, configured to a predefined timeout period and is constantly running when enabled. if the wdt is not reset within the timeout peri od, it will issue a system reset. the wdt is reset by executing the wdr (watchdog timer reset) instruction from the application code. the wdt also has a window mode that enables the user to define a time slot where wdt must be reset within. if the wdt is reset too ea rly or too late, a system reset will be issued. the wdt will run in all power modes if enabled. it runs from a cpu independent clock source, and will continue to operate to issue a syst em reset even if th e main clocks fail. the configuration change protection mechanism ensures that the wdt settings cannot be changed by accident. in addition the settings can be locked by a fuse. 9.3 normal mode operation in normal mode operation a single timeout period is set for the wdt. if the wdt is not reset from the application code bef ore the timeout occurs the wdt will i ssue a system reset. there are 11 possible wdt timeout (to wdt ) periods selectable from 8 ms to 8s, and the wdt can be reset at any time during the period. after each reset, a new timeout period is started. the default timeout period is controlled by fuses. norm al mode operation is illustrated in figure 9-1 . figure 9-1. normal mode operation. t [ms] wdt count 510 15 20 25 30 35 to wdt = 16 timely wdt reset to wdt wdt timeout system reset
90 8210b?avr?04/10 xmega d 9.4 window mode operation in window mode operation the wd t uses two different timeout peri ods, a "closed" window time- out period (to wdtw ) and the normal timeout period (to wdt ). the closed window timeout period defines a duration from 8 ms to 8s where the wdt cannot be reset: if the wdt is reset in this period the wdt will issue a system reset. the norma l wdt timeout period, which is also 8 ms to 8s, defines the duration of the "open" period, in which the wdt can (and should) be reset. the open period will always follow the closed period, so the total duration of the timeout period is the sum of the closed window and the open window timeout periods. the default closed window tim- eout period is controlled by fuses. the window mode operatio n is illustrated in figure 9-2 . figure 9-2. window mode operation. 9.5 watchdog timer clock the wdt is clocked from the 1 khz output from the internal 32 khz ultra low power (ulp) oscil- lator. due to the ultra low power design, the osc illator is not very accurate so the exact timeout period may vary from device to device. w hen designing software which uses the wdt, this device-to-device variation must be kept in mind to ensure that the timeout periods used are valid for all devices. for more in formation on the ulp oscillato r accuracy, consult the device datasheet. 9.6 configuration protection and lock the wdt is designed with two security mechanisms to avoid unintentional changes of the wdt settings. the first mechanism is the configuration change protection mechanism, employing a timed write procedure for changing the wdt control registers. in addition, for the new configuration to be written to the control registers, the register?s change enable bit must be written at the same time. the second mechanism is to lock the configurat ion by setting the wdt lock fuse. when this fuse is set, the watchdog time control register can not be changed, hence the wdt can not be dis- abled from software. a fter system reset the wdt will resume at configured operation. when the wdt lock fuse is programmed the window mode timeout period cannot be changed, but the win- dow mode itself can still be enabled or disabled. t [ms] wdt count 510 15 20 25 30 35 to wdtw = 8 to wdt = 8 timely wdt reset closed to wdtw open to wdt early wdt reset system reset
91 8210b?avr?04/10 xmega d 9.7 registers description 9.7.1 ctrl ? watchdog timer control register ? bits 7:6 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bits 5:2 - per[3:0]: watchdog timeout period these bits determine the watchd og timeout period as a number of 1 khz ulp oscillator cycles. in window mode operation, these bits define the open window period. the different typical time- out periods are found in table 9-1 . the initial values of these bits are set by the watchdog timeout period (wdp) fuses, and will be loaded at power-on. in order to change these bits the cen bit must be written to 1 at the same time. these bits are protected by the configuration change protection mechanism, for detailed description refer to ?configuration change protection? on page 12 . bit 76543210 +0x00 ? ? per[3:0] enable cen ctrl read/write (unlocked) r r r/w r/w r/w r/w r/w r/w read/write (locked) rrrrrrrr initial value (x = fuse) 0 0xxxxx0 table 9-1. watchdog timeout periods per[3:0] group configuration typical timeout periods 0000 8clk 8 ms 0001 16clk 16 ms 0010 32clk 32 ms 0011 64clk 64 ms 0100 125clk 0.125 s 0101 250clk 0.25 s 0110 500clk 0.5 s 0111 1kclk 1.0 s 1000 2kclk 2.0 s 1001 4kclk 4.0 s 1010 8kclk 8.0 s 1011 reserved 1100 reserved 1101 reserved 1110 reserved 1111 reserved
92 8210b?avr?04/10 xmega d ? bit 1 - enable: watchdog enable this bit enables the wdt. in order to change this bit the cen bit in ?ctrl ? watchdog timer control register? on page 91 must be written to one at the same time. this bit is protected by the configuration change pro- tection mechanism, for detailed description refer to ?configuration change protection? on page 12 . ? bit 0 - cen: watchdog change enable this bit enables the possibility to change the configuration of the ?ctrl ? watchdog timer con- trol register? on page 91 . when writing a new value to this register, this bit must be written to one at the same time for the changes to take effect. this bit is protected by the configuration change protection mechanism, for detailed description refer to ?configuration change protec- tion? on page 12 . 9.7.2 winctrl ? window mode control register ? bits 7:6 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bits 5:2 - wper[3:0]: watchdog window mode timeout period these bits determine the closed window period as a number of 1 khz ulp oscillator cycles in window mode operation. the typical different closed window periods are found in table 9-2 . the initial values of these bits are set by the watchdog window timeout period (wdwp) fuses, and will be loaded at power-on . in normal mode these bits are not in use. in order to change these bits the wcen bit must be written to one at the same time. these bits are protected by the configuration change protection mechanism, for detailed description refer to ?configuration change protection? on page 12 . bit 76543210 +0x01 ? ? wper[3:0] wen wcen winctrl read/write (unlocked) r r r/w r/w r/w r/w r/w r/w read/write (locked) rrrrrrr/wr/w initial value (x = fuse) 0 0xxxxx0 table 9-2. watchdog closed window periods wper[3:0] group configuration typ ical closed window periods 0000 8clk 8 ms 0001 16clk 16 ms 0010 32clk 32 ms 0011 64clk 64 ms 0100 125clk 0.125 s 0101 250clk 0.25 s
93 8210b?avr?04/10 xmega d ? bit 1 - wen: watchdog window mode enable this bit enables the watchdog window mode. in order to change this bit the wcen bit in ?winctrl ? window mode control register? on page 92 must be written to one at the same time. this bit is protected by the configur ation change protection mechanism, for detailed description refer to ?configuration change protection? on page 12 . ? bit 0 - wcen: watchdog window mode change enable this bit enables the possibility to change the configuration of the ?winctrl ? window mode control register? on page 92 . when writing a new value to this register, this bit must be written to one at the same time for the changes to take effect. this bit is protected by the configuration change protection mechanism, but not protected by the wdt lock fuse. 9.7.3 status ? watchdog status register ? bit 7:1 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 0 - syncbusy when writing to the ctrl or winctrl registers, the wdt needs to be synchronized to the other clock domains. duri ng synchronization the syncbusy bit will be read as one. this bit is automatically cleared after the syn chronization is finished. synchr onization will only take place when the enable bit for the watchdog timer is set. 0110 500clk 0.5 s 0111 1kclk 1.0 s 1000 2kclk 2.0 s 1001 4kclk 4.0 s 1010 8kclk 8.0 s 1011 reserved 1100 reserved 1101 reserved 1110 reserved 1111 reserved table 9-2. watchdog closed window periods (continued) wper[3:0] group configuration typ ical closed window periods bit 7654321 0 +0x02 ? ? ? ? ? ? ? syncbusy status read/write rrrrrrr r initial value 0 0 0 0 0 0 0 0
94 8210b?avr?04/10 xmega d 9.8 register summary address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 ctrl ? ? per[3:0] enable cen 91 +0x01 winctrl ? ? wper[3:0] wen wcen 92 +0x02 status ? ? ? ? ? ? ? syncbusy 93
95 8210b?avr?04/10 xmega d 10. interrupts and programmable mu lti-level interrupt controller 10.1 features ? separate interrupt vector for each interrupt ? short, predictable in terrupt response time ? programmable multi-level interrupt controller ? 3 programmable interrupt levels ? selectable priority scheme within low level interrupts (round-robin or fixed) ? non-maskable interrupts (nmi) ? interrupt vectors can be moved to the start of the boot section. 10.2 overview interrupts signal a change of state in peripherals, and this can be used to alter program execu- tion. peripherals can have one or more interrupts, and all are individually enabled. when the interrupt is enabled and the inte rrupt condition is present this will generate a corr esponding inter- rupt request. all interrupts have a separate interrupt vector address. the programmable multi-level in terrupt controller (pmic) contro ls the handling of interrupt requests, and prioritizing between the different interrupt levels and interrupt priorities. when an interrupt request is acknowledged by the pmic, the program counter is set to point to the inter- rupt vector, and the interrupt handler can be executed. all peripherals can select between three different priority levels for thei r interrupts; low, medium or high. medium level interrupts will interrupt low level interrupt handlers. high level interrupts will interrupt both medium and low level interrupt handler s. within each level, the interrupt prior- ity is decided from the interrupt vector address, where the lowest interrupt vector address has the highest interrupt priority. low level interrupts have an optional round-robin scheduling scheme to ensure that all interrupts are serviced within a certain amount of time. non-maskable interrupts (nmi) are also supported. 10.3 operation interrupts must be globally enabled for any interrupts to be generated. this is done by setting the global interrupt enable bit (i-bit) in the cp u status register. the i-bit will not be cleared when an interrupt is acknowledged. each interrupt level must also be enabled before interrupts with the corresponding level can be generated. when an interrupt is enabled and the interrupt cond ition is present, the pmic will receive the interrupt request. based on the interrupt level and interrupt priority of any ongoing interrupts, the interrupt is either acknowledged or kept pending until it has priority. when the interrupt request is acknowledged, the program counter is updated to point to the interrupt vector. the interrupt vector is normally a jump to the interrupt handler; the software routine that handles the interrupt. after returning from the interrupt handler, program execution continues from where it was before the interrupt occurred. one instruction is always executed before any pending interrupt is served. the pmic status register contains state informat ion that ensures that the pmic returns to the correct interrupt level when the reti (interrupt return) instruction is executed at the end of an interrupt handler. returnin g from an interrupt will return the pmic to the state it had before enter- ing the interrupt. the status register (sre g) is not saved automatically upon an interrupt
96 8210b?avr?04/10 xmega d request. the ret (subroutine return) instructi on cannot be used when returning from the inter- rupt handler routine, as this will not return the pmic to its right state. 10.4 interrupts all interrupts and the reset vector each have a separate program vector address in the program memory space. the lowest address in the program memory space is the reset vector. all inter- rupts are assigned individual control bits for enabling and setting the interrupt level, and this is set in the control registers for each peripheral that can generate interrupts. details on each inter- rupt are described in the peripheral where the interrupt is available. all interrupts have an interrupt flag associated to it. when the interrupt condition is present, the interrupt flag will be set, even if the corresponding interrupt is not enabled. for most interrupts, the interrupt flag is automatically cleared when executing the interrupt vector. writing a logical one to the interrupt flag will also clear the flag. some interrupt fl ags are not clear ed when execut- ing the interrupt vector, and some are cleared automatically when an associated register is accessed (read or written). this is descri bed for each individual interrupt flag. if an interrupt condition occurs while another higher priority interrupt is executing or pending, the interrupt flag will be set and remembered until the interrupt has priority. if an interrupt condition occurs while the corresponding in terrupt is not enabled, the inte rrupt flag will be set and remem- bered until the interrupt is enabled, or the flag is cleared by software. similarly, if one or more interrupt conditions occur while global interrupts are disabled, the corresponding interrupt flag will be set and remembered until global interrupts are enabled. all pending interrupts are then executed according to their order of priority. interrupts can be blocked when executing code from a locked section, e.g. when the boot lock bits are programmed. this feature improves software security, refer to memory programming for details on lock bit settings. interrupts are automatically di sabled for up to 4 cpu clock cycles when the configuration change protection register is written with the correct signature, refer to ?configuration change protection? on page 12 for more details. 10.4.1 nmi ? non-maskable interrupts non-maskable interrupts (nmi) are hardwired. it is not selectable which interrupts represent nmi and which represent regular interrupts. non-maskable interrupts must be enabled before they can be used. refer to the device datasheet for nmi present on each the device. a nmi will be executed regard less of the setting of the i-bit, a nd it will never change the i-bit. no other interrupts can interrupt a nmi interrupt handler. 10.4.2 interrupt response time the interrupt response time for all the enabled interrupts is five cpu clock cycles minimum. dur- ing these five clock cycles the program counter is pushed on the stack. after five clock cycles, the program vector for the interrupt is executed. the jump to the interrupt handler takes three clock cycles. if an interrupt occurs during execution of a mult i-cycle instruction, this instruction is completed before the interrupt is served. if an interrupt occurs when the device is in sleep mode, the inter- rupt execution response time is increased by fi ve clock cycles. in addition the response time is increased by the start-up time from the selected sleep mode.
97 8210b?avr?04/10 xmega d a return from an interrupt handling routine takes fi ve clock cycles. during these five clock cycles, the program counter is popped from the stack and the stack pointer is incremented. 10.5 interrupt level the interrupt level is independently selected for each interrupt source. for any interrupt request, the pmic also receives the interrupt level for the interrupt. the interrupt levels and their corre- sponding bit values for the interrupt level configuration of all interrupts is shown in table 10-1 . the interrupt level of an interrupt request is compared against the current level and status of the interrupt controller. an interrupt request on higher level will interrupt any ongoing interrupt han- dler from a lower level interrupt. when returning from the higher level interrupt handler, the execution of the lower level interrupt handler will continue. 10.6 interrupt priority within each interrupt level, all interrupts have a priority. when several interrupt requests are pending, the order of which interrupts are acknowledged is decided both by the level and the pri- ority of the interrupt request. interrupts can be organized in a static or dynamic (round-robin) priority scheme. high and medium level interrupts and the nmi will always have static priority. for low level interrupts, static or dynamic priority scheduling can be selected. 10.6.1 static priority interrupt vectors (ivec) are located at fixed addresses. for static priority, the interrupt vector address decides the priority within one interrupt level where the lowest interrupt vector address has the highest priority. refer to the device datasheet for interrupt vector table with the base address for all modules and peripheral s with interrupt. refer to the interrupt vector summary of each module and peripheral in this manual for a list of interrupts and their corresponding offset address within the different modules and peripherals. table 10-1. interrupt level interrupt level configuration group configuration description 00 off interrupt disabled. 01 lo low level interrupt 10 med medium level interrupt 11 hi high level interrupt
98 8210b?avr?04/10 xmega d figure 10-1. static priority. 10.6.2 round-robin scheduling to avoid the possible starvation problem for low level interrupts with static priority, the pmic gives the possibility for round-r obin scheduling for low level inte rrupts. when round-robin sched- uling is enabled, the interrupt vector address for the last acknowledged low level interrupt will have the lowest priority next time one or mo re interrupts from the low level is requested. figure 10-2. round-robin scheduling. ivec 0 : : : ivec x ivec x+1 : : : ivec n lowest priority highest priority lowest address highest address highest priority iv ec 0 : : : iv ec x iv ec x +1 : : : iv ec n iv ec 0 : : : iv ec x iv ec x +1 : : : iv ec n highest priority low est priority iv ec x +2 ivec x+1 last acknow ledged interrupt low est priority ivec x last acknow ledged interrupt
99 8210b?avr?04/10 xmega d 10.7 moving interrupts between a pplication and boot section the interrupt vectors can be moved from the default location in the application section in flash to the start of the boot section. 10.8 register description 10.8.1 status - pmic status register ? bit 7 - nmiex: non-maskable interrupt executing this flag is set if a non-maskable interrupt is executing. the flag will be cleared when returning (reti) from the interrupt handler. ? bit 6:3 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 2 - hilvlex: high level interrupt executing this flag is set if a high level interrupt is executing or the interrupt handler has been interrupted by an nmi. the flag will be cleared when return ing (reti) from th e interrup t handler. ? bit 1 - medlvlex: medium level interrupt executing this flag is set if a medium level interrupt is executing or the interrupt handler has been inter- rupted by an interrupt from highe r level or an nmi. the flag will be cleared when returning (reti) from the interrupt handler. ? bit 0 - lolvlex: low level interrupt executing this flag is set if a low level in terrupt is executing or the interrupt handler has been interrupted by an interrupt from higher level or an nmi. the flag will be cleared when returning (r eti) from the interrupt handler. 10.8.2 intpri - pmic priority register ? bit 7:0 - intpri: interrupt priority when round-robin scheduling is enabled, this register stores the interrupt vector of the last acknowledged low-level interrupt. the stored interrupt vector will have the lowest priority next time one or more low-level interrupts are pending. the register is accessible from software to bit 765432 1 0 +0x00 nmiex ? ? ? ? hilvlex medlvlex lolvlex status read/write rrrrrr r r initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x01 intpri[7:0] intpri read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 00000000
100 8210b?avr?04/10 xmega d change the priority queue. this register is not reinitialized to its init ial value if round-robing scheduling is disabled, so if default static priority is needed the register must be written to zero. 10.8.3 ctrl - pmic control register ? bit 7 - rren: round-robin scheduling enable when the rren bit is set the round-robin schedu ling scheme is enabled fo r low level interrupts. when this bit is cleared, the priority is static according to interrupt vector address where the low- est address has the highest priority. ? bit 6 - ivsel: interrupt vector select when the ivsel bit is cleared (zero), the interrupt vectors are placed at the start of the applica- tion section in flash. when this bit is set (one), the interrupt vectors are moved to the beginning of the boot section of the flash. refer to the device datasheet for the absolute address. this bit is protected by the configuratio n change protection mechanism, refer to ?configuration change protection? on page 12 for details. ? bit 5:3 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 2 - hilvlen: high level interrupt enable when this bit is set all high level interrupts are enabled. if this bit is cleared, high level interrupt requests will be ignored. ? bit 1 - medlvlen: medium level interrupt enable when this bit is set all medium level interrupts ar e enabled. if this bit is cleared, medium level interrupt requests will be ignored. ? bit 0 - lolvlen: low level interrupt enable when this bit is set all low level interrupts are enabled. if this bit is cleared, low level interrupt requests will be ignored. 10.9 register summary bit 765432 1 0 +0x02 rren ivsel ? ? ? hilvlen medlvlen lolvlen ctrl read/write r/w r/w r r r r/w r/w r/w initial value 000000 0 0 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 status nmiex ? ? ? ? hilvlex medlvlex lolvlex 99 +0x01 intpri intpri[7:0] 99 +0x02 ctrl rren ivsel ? ? ? hilvlen medlvlen lolvlen 100
101 8210b?avr?04/10 xmega d 11. i/o ports 11.1 features ? selectable input and output configuration for each pin individually ? flexible pin configuration through dedicated pin configuration register ? synchronous and/or asynchronous input sensing with port interrupts and events ? asynchronous wake-up signalling ? highly configurable output driver and pull settings: ? totem-pole ? pull-up/-down ? wired-and ? wired-or ? bus keeper ? inverted i/o ? flexible pin masking ? configuration of multiple pins in a single operation ? read-modify-write (rmw) support ? toggle/clear/set registers for out and dir registers ? clock output on port pin ? event channel 0 output on port pin 7 ? mapping of port registers (virtual port s) into bit accessible i/o memory space 11.2 overview xmega has flexible general purpose i/o (gpio) ports. a port consists of up to 8 pins ranging from pin 0 to 7, where each pin can be confi gured as input or output with highly configurable driver and pull settings. the ports also implement several functions including interrupts, synchro- nous/asynchronous input sensing an d asynchronous wa ke-up signalling. all functions are individual per pin, but several pi ns may be configured in a single operation. all ports have true read-modify-write (rmw) functionality when used as general purpose i/o ports. the direction of one port pin can be changed without unintentionally changing the direction of any other pin. the same applies when changing drive value when configured as output, or enabling/disabling of pull-up or pull-down resistors when configured as input. figure 11-1 on page 102 shows the i/o pin functionality, and t he registers that is available for controlling a pin.
102 8210b?avr?04/10 xmega d figure 11-1. general i/o pin functionality. 11.3 using the i/o pin use of an i/o pin is controlled from the user software. each port has one data direction (dir), data output value (out) that is used for port pin control. the data input value (in) register is used for reading the port pins. in addition each pin has a pin configuration (pinnctrl) register for additional pin configuration. direction of the pin is decided by the dirn bit in the dir register. if dirn is written to one, pin n is configured as an output pin. if dirn is written to zero, pin n is configured as an input pin. when direction is set as output, the outn bit in out is used to set the value of the pin. if outn is written to one, pin n is driven high. if ou tn is written to zero , pin n is driven low. the in register is used for reading the pin value. the pin value can always be read regardless of the pin being configured as input or output, except if digital input is disabled. i/o pins are tri-stated when reset condition becomes active, even if no clocks are running. d q r d q r synchronizer d q r d q r dirn outn pinnctrl inn pxn d q r input disable wired and/or digital input pin analog input/output inverted i/o pull enable pull keep pull direction
103 8210b?avr?04/10 xmega d 11.4 i/o pin configuration the pin n configuration (pinnctrl) register is us ed for additional i/o pin configuration. a pin can be set in a totem-pole, wired -and, or wired-or configuration. it is also possible to enable inverted input and output for the pin. for totem-pole output there are four possible pull configurations: totem-pole (push-pull), pull- down, pull-up and bus-keeper. the bus-keeper is active in both directions. this is to avoid oscil- lation when disabling the output. the totem-pole configurations with pull-up and pull-down only have active resistors when the pin is set as input. this feature eliminates unnecessary power consumption. for wired-and and wired-or configuration, the optional pull-up and pull-down resistors are active in both input and output direction. since pull configuration is configured through the pin configuration register, all intermediate port states during switching of pin direction and pin values are avoided. the i/o pin configurations are summarized with simplified schematics from figure 11-2 on page 103 to figure 11-7 on page 105 . 11.4.1 totem-pole figure 11-2. i/o pin configuration - totem-pole (push-pull). 11.4.2 pull-down figure 11-3. i/o pin configuration - totem-pole with pull-down (on input). inn outn dirn pn inn outn dirn pn
104 8210b?avr?04/10 xmega d 11.4.3 pull-up figure 11-4. i/o pin configuration - totem-pole with pull-up (on input). 11.4.4 bus-keeper the bus-keeper?s week output produces the same logi cal level as the last output level. it acts as a pull-up if the last leve l was '1', and pull-down if the last level was '0'. figure 11-5. i/o pin configuration - totem-pole with bus-keeper. inn outn dirn pn inn outn dirn pn
105 8210b?avr?04/10 xmega d 11.4.5 wired-or figure 11-6. output configuration - wired-or with optional pull-down. 11.4.6 wired-and figure 11-7. output configuration - wired-and with optional pull-up. 11.5 reading the pin value independent of the pin data direction, the pin value can be read from the in register as shown in figure 11-1 on page 102 . if the digital input is disabled, the pin value cannot be read. the in register bit and the preceding flip-flop constitu te a synchronizer. the synchronizer is needed to avoid metastability if the physical pin changes value near the edge of the internal clock. the synchronizer introduces a delay on the internal signal line. figure 11-8 on page 106 shows a timing diagram of the synchronization when reading an externally applied pin value. the maxi- mum and minimum propagation delays are denoted t pd,max and t pd,min respectively. inn outn pn inn outn pn
106 8210b?avr?04/10 xmega d figure 11-8. synchronization when reading an externally applied pin value. 11.6 input sense configuration input sensing is used to detect an edge or level on the i/o pin input. the different sense configu- rations that are available for ea ch pin are detection of rising edge, falling edge or both edges, or detection of low level. high level can be detecte d by using inverted input. input sensing can be used to trigger interrupt requests (ireq) or s when there is a change on the pin. the i/o pins support synchronous and asynchronous input sensing. synchronous sensing requires presence of the peripheral clock, while asynchronous sensing does not require any clock. figure 11-9. input sensing. peripheral clk instructions sync flipflop in r17 xxx xxx lds r17, portx+in t pd, max t pd, min 0x00 0xff inverted i/o interrupt control ireq event pn d q r d q r synchronizer inn edge detect asynchronous sensing synchronous sensing edge detect
107 8210b?avr?04/10 xmega d 11.7 port interrupt each port has two interrupt vectors, and it is configurable which pins on the port that can be used to trigger each interrupt request. port interrupts must be enabled before they can be used. which sense configurations that can be used to generate interrupts is dependent on whether synchronous or asynchronous input sensing is used. for synchronous sensing, all sense configurations can be used to generate interrupts. for edge detection, the changed pin value must be sampled once by the peripheral clock for an interrupt request to be generated. for asynchronous sensing, only port pin 2 on each port has full asynchronous sense support. this means that for ed ge detection, pin 2 will de tect and latch any edge and it will a lways trigger an interrupt request. the other port pins have limited asynchronous sense support. this means that for edge detection the changed value must be held until the device wakes up and a clock is present. if the pin value returns to its initial value before the end of the device start-up time, the device will still wake up, but no in terrupt request will be generated. a low level can always be detected by all pins, regardless of a peripheral clock being present or not. if a pin is configured for lo w level sensing, the in terrupt will trigger as lo ng as the pin is held low. in active mode the low level must be kept until the completion of the currently executing instructions for an interrupt to be generated. in all sleep modes the low level must be kept until the end of the device start-up time for an interrupt to be generated. if the low level disappears before the end of the st art-up time, the device will still wa ke up, but no interrupt will be generated. table 11-1 , table 11-2 , and table 11-3 on page 108 summarizes when interrupts can be trig- gered for the various input sense configurations. table 11-1. synchronous sense support sense settings supported i nterrupt description rising edge yes always triggered falling edge yes always triggered both edges yes always triggered low level yes pin-level must be kept unchanged. table 11-2. full asynchronous sense support sense settings supported i nterrupt description rising edge yes always triggered falling edge yes always triggered both edges yes always triggered low level yes pin-level must be kept unchanged.
108 8210b?avr?04/10 xmega d 11.8 port event port pins can generate an event when there is a change on the pin. the sense configurations decide when each pin will generat e events. event generation requi res the presence of a periph- eral clock, hence asynchronous event generation is not possible. for edge sensing, the changed pin value must be sampled once by the peripheral clock for an event to be generated. for low level sensing, events gene ration will follow the pin value. a pin change from high to low (falling edge) will not generate an event, the pin change must be from low to high (rising edge) for events to be generated. in order to generate events on falling edge, the pin configuration must be set to inverted i/o. a low pin value will not ge nerate events, and a high pin value will cont inuously generate events. 11.9 alternate port functions most port pins have alternate pin functions in addition to being a general purpose i/o pin. when an alternate function is enabled this might overri de the normal port pin function or pin value. this happens when other peripherals that require pins are enabled or configured to use pins. if, and how a peripheral will override an d use pins is described in section for that peripheral. the port override signals and related logic (grey) is shown in figure 11-10 on page 109 . these signals are not accessible from software, but are internal signals between the overriding periph- eral and the port pin. table 11-3. limited asynchronous sense support sense settings supported i nterrupt description rising edge no - falling edge no - both edges yes pin value must be kept unchanged. low level yes pin-level must be kept unchanged.
109 8210b?avr?04/10 xmega d figure 11-10. port override signals and related logic 11.10 clock and event output it is possible to output both the peripheral cl ock and the signaling event from event channel 0 to pin. output port pin is sele cted from software. if an event occur on event channel 0, this will be visible on the port pin as long as the event last. normally this is one peripheral clock cycle only. 11.11 multi-configuration mpcmask can be used to set a bi t mask for the pin configuration registers. when setting bit n in mpcmask, pinnctrl is added to the pin configuration mask. duri ng the next wr ite to any of the port's pin config uration registers, the same value will be written to all the port's pin configura- tion registers set by the mask. the mpcmask register is cleared automatically after the write operation to the pin configuration registers is finished. d q r d q r synchronizer d q r d q r dirn outn pinnctrl inn pxn d q r digital input disable (did) wired and/or digital input pin analog input/output inverted i/o did override value out override enable out override value dir override value dir override enable did override enable pull enable pull keep pull direction
110 8210b?avr?04/10 xmega d 11.12 virtual registers virtual port registers allows for port registers in the extended i/o memory space to be mapped virtually in the i/o memory space. when mapping a port, writing to the virtual port register will be the same as writing to the real port register. this enables use of i/o memory specific instructions for bit-manipulation, and the i/o memory specific instructions in and out on port register that normally resides in the extended i/o memory space. there are four virtual ports, so up to four ports can be mapped virtually at the same time. the mapped registers are in, out, dir and intflags. 11.13 register d escription ? ports 11.13.1 dir - data direction register ? bit 7:0 - dir[7:0]: data direction this register sets the data direction for the individua l pins in the port. if dirn is written to one, pin n is configured as an output pin. if dirn is written to zero, pin n is configured as an input pin. 11.13.2 dirset - data direction set register ? bit 7:0 - dirset[7:0]: port data direction set this register can be used instead of a read-modify-write to set individual pins as output. writing a one to a bit will set the corresponding bit in th e dir register. reading this register will return the value of the dir register. 11.13.3 dirclr - data di rection clear register ? bit 7:0 - dirclr[7:0]: po rt data direction clear this register can be used instead of a read-modify-write to set individual pins as input. writing a one to a bit will clear the corresponding bit in the dir register. reading this register will return the value of the dir register. bit 76543210 +0x00 dir[7:0] dir read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x01 dirset[7:0] dirset read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x02 dirclr[7:0] dirclr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000
111 8210b?avr?04/10 xmega d 11.13.4 dirtgl - data direction toggle register ? bit 7:0 - dirtgl[7:0]: port data direction toggle this register can be used instead of a read-modify-write to toggle the direction on individual pins. writing a one to a bit will toggle the corres ponding bit in the dir register. reading this reg- ister will return the valu e of the dir register. 11.13.5 out - data output value ? bit 7:0 - out[7:0]: port data output value this register sets the data output value for the i ndividual pins in the port. if outn is written to one, pin n is driven high. if outn is written to zero, pin n is driven low. for this setting to have any effect the pin direction must be set as output. 11.13.6 outset - data output value set register ? bit 7:0 - outset[7:0]: data output value set this register can be used instead of a read-modi fy-write to set the output value on individual pins to one. writing a one to a bit will set the corresponding bit in the out register. reading this register will return the value in the out register. 11.13.7 outclr - data output value clear register bit 76543210 +0x03 dirtgl[7:0] dirtgl read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x04 out[7:0] out read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x05 outset[7:0] outset read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x06 outclr[7:0] outclr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
112 8210b?avr?04/10 xmega d ? bit 7:0 - outclr[7:0]: data output value clear this register can be used instead of a read-modi fy-write to set the output value on individual pins to zero. writing a one to a bit will clear the corresponding bit in the out register. reading this register will re turn the value in the out register. 11.13.8 outtgl - data output value toggle register ? bit 7:0 - outtgl[7:0]: port data output value toggle this register can be used instead of a read-modify-write to toggle the output value on individual pins. writing a one to a bit will toggle the corresp onding bit in the out regi ster. reading this reg- ister will return the valu e in the out register. 11.13.9 in - data input value register ? bit 7:0 - in[7:0]: data input value this register shows the value present on the pins if the digital input driver is enabled. inn shows the value of pin n on the port. 11.13.10 intctrl - interrupt control register ? bit 7:4 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 3:2/1:0 - intnlvl[1:0]: interrupt n level these bits enable interrupt request for port interrupt n and select the interrupt level as described in section 11. ?interrupts and programmable multi-level interrupt controller? on page 117 . bit 76543210 +0x07 outtgl[7:0] outtgl read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x08 in[7:0] in read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x09 ? ? ? ? int1lvl[1:0] int0lvl[1:0] intctrl read/write r r r r r/w r/w r/w r/w initial value00000000
113 8210b?avr?04/10 xmega d 11.13.11 int0mask - interrupt 0 mask register ? bit 7:0 - int0msk[7:0]: interrupt 0 mask register these bits are used to mask which pins can be used as sour ces for port interrupt 0. if int0maskn is written to one, pin n is used as source for port interr upt 0.the input sense config- uration for each pin is decided by the pinnctrl-registers. 11.13.12 int1mask - interrupt 1 mask register ? bit 7:0 - int1mask[7:0]: interrupt 1 mask register these bits are used to mask which pins can be used as sour ces for port interrupt 1. if int1maskn is written to one, pin n is used as source for port interr upt 1.the input sense config- uration for each pin is decided by the pinnctrl-registers. 11.13.13 intflags - interrupt flag register ? bit 7:2 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 1:0 - intnif: interrupt n flag the intnif flag is set when a pin change according to the pin's input sense configuration occurs, and the pin is set as source for port interrupt n. writing a one to this flag's bit location will clear the flag. for enabling and executing the interrupt refer to the interrupt level description. bit 76543210 +0x0a int0msk[7:0] int0mask read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x0b int1msk[7:0] int1mask read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x0c ? ? ? ? ? ? int1if int0if intflags read/writerrrrrrr/wr/w initial value00000000
114 8210b?avr?04/10 xmega d 11.13.14 pinnctrl - pin n configuration register ? bit 7 - reserved this bit is reserved and will a lways be read as zero. for compat ibility with future devices, always write this bit to zero when this register is written. ? bit 6 - inven: inverted i/o enable setting this bit will enable invertin g output and input data on pin n. ? bit 5:3 - opc: output and pull configuration these bits sets the output/pull configuration on pin n according to table 11-4 . ? bit 2:0 - isc[2:0]: input/sense configuration these bits sets the input and sense configuration on pin n according to table 11-5 . the sense configuration decides how the pin can trigger port interrupts and events. when the input buffer is not disabled, the schmitt triggered input is sampled (synchronized) and can be read in the in register. bit 76543210 ? inven opc[2:0] isc[2:0] pinnctrl read/write r r/w r/w r/w r/w r/w r/w r/w initial value00000000 table 11-4. output/pull configuration opc[2:0] group configuration description output configuration pull configuration 000 totem totempole (n/a) 001 buskeeper totempole bus keeper 010 pulldown totempole pull-down (on input) 011 pullup totempole pull-up (on input) 100 wiredor wired or (n/a) 101 wiredand wired and (n/a) 110 wiredorpull wired or pull-down 111 wiredandpull wired and pull-up table 11-5. input/sense configuration isc[2:0] group configuration description 000 bothedges sense both edges 001 rising sense rising edge 010 falling sense falling edge 011 level sense low level (1) 100 reserved
115 8210b?avr?04/10 xmega d note: 1. a low pin value will not generate events, and a high pin value will continuously generate events. 2. only port a - f supports the input buffer disable option. 11.14 register descr iption ? multipor t configuration 11.14.1 mpcmask - multi-pin configuration mask register ? bit 7:0 - mpcmask[7:0]: multi-pin configuration mask the mpcmask register enables severa l pins in a port to be configur ed at the same time. writing a one to bit n allows that pin to be part of the multi-pin configuration. when a pin configuration is written to one of the pinnctrl registers of the port, that value is written to all the pinnctrl registers of the pins matching t he bit pattern in the mp cmask register for that port. it is not nec- essary to write to one of the registers that is set by the mpcmask register. the mpcmask register is automatically cleared afte r any pinnctrl regi sters is written. 11.14.2 vpctrla - virtual port-map control register a ? bit 7:4 - vp1map: vi rtual port 1 mapping these bits decide which ports should be mapped to virtual port 1. the registers dir, out, in and intflags will be mapped. acce ssing the virtual port register s is equal to accessing the actual port registers. see table 11-6 for configuration. ? bit 3:0 - vp0map: vi rtual port 0 mapping these bits decide which ports should be mapped to virtual port 0. the registers dir, out, in and intflags will be mapped. acce ssing the virtual port register s is equal to accessing the actual port registers. see table 11-6 for configuration. 101 reserved 110 reserved 111 intput_disable input buffer disabled (2) table 11-5. input/sense configuration isc[2:0] group configuration description bit 76543210 +0x00 mpcmask[7:0] mpcmask read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x02 vp1map[3:0] vp0map[3:0] vpctrla read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
116 8210b?avr?04/10 xmega d 11.14.3 vpctrlb - virtual port-map control register b ? bit 7:4 - vp3map: vi rtual port 3 mapping these bits decide which ports should be mapped to virtual port 3. the registers dir, out, in and intflags will be mapped. acce ssing the virtual port register s is equal to accessing the actual port registers. see table 11-6 for configuration. ? bit 3:0 - vp2map: vi rtual port 2 mapping these bits decide which ports should be mapped to virtual port 2. the registers dir, out, in and intflags will be mapped. acce ssing the virtual port register s is equal to accessing the actual port registers. see table 11-6 for configuration. 11.14.4 clkevout - clock and event out register bit 76543210 +0x03 vp3map[3:0] vp2map[3:0] vpctrlb read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 table 11-6. virtual port mapping. vpnmap[3:0] group configuration description 0000 porta porta mapped to virtual port n 0001 portb portb mapped to virtual port n 0010 portc portc mapped to virtual port n 0011 portd portd mapped to virtual port n 0100 porte porte mapped to virtual port n 0101 portf portf mapped to virtual port n 0110 portg portg mapped to virtual port n 0111 porth porth mapped to virtual port n 1000 portj portj mapped to virtual port n 1001 portk portk mapped to virtual port n 1010 portl portl mapped to virtual port n 1011 portm portm mapped to virtual port n 1100 portn portn mapped to virtual port n 1101 portp portp mapped to virtual port n 1110 portq portq mapped to virtual port n 1111 portr portr mapped to virtual port n bit 76543210 +0x04 ? ? evout[1:0] clkoutsel[1:0] clkout[1:0] clkevout read/write r r r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
117 8210b?avr?04/10 xmega d ? bit 7:6 - reserved these bits are reserved and will always be read as one. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 5:4 - evout[1:0] - event output port these bits decide which port the event channel 0 from the event system should be output to. pin 7 on the selected port is always used, and the clkout bits must be set different from evout. the pin must be configured as an output pin for the signaling event to be available on the pin. table 11-7 on page 117 shows the possible configurations. ? bits 3:2 - clkoutsel[1:0] - clock output select these bits are used to select which clock is output to pin. ? bit 1:0 - clkout[1:0] - clock output port these bits decide which port the peripheral cloc k should be output to. pin 7 on the selected port is always used. the clock output setting, will ov erride the event output setting, thus if both are enabled on the same port pin, the peripheral clock will be vi sible. the pin must be configured as an output pin for the clock to be available on the pin. table 11-9 on page 117 shows the possible configurations. table 11-7. event channel 0 output configurations evout[1:0] group configuration description 00 off event out disabled 01 pc7 event channel 0 output on port c pin 7 10 pd7 event channel 0 output on port d pin 7 11 pe7 event channel 0 output on port e pin 7 table 11-8. clock output select clkoutsel[1:0] group co nfiguration description 00 clk1x clk per output to pin 01 clk2x clk per2 output to pin 10 clk4x clk per4 output to pin table 11-9. clock output configurations clkout[1:0] group configuration description 00 off clock out disabled 01 pc7 clock output on port c pin 7 10 pd7 clock output on port d pin 7 11 pe7 clock output on port e pin 7
118 8210b?avr?04/10 xmega d 11.15 register descrip tion ? virtual port 11.15.1 dir - data direction ? bit 7:0 - dir[7:0]: data direction register this register sets the data direction for the individual pins in the port mapped by "vpctrla - virtual port-map control register a" or "vpctr lb - virtual port-map control register b". when a port is mapped as virtual, accessing this regist er is identical to accessing the actual dir regis- ter for the port. 11.15.2 out - data output value ? bit 7:0 - out[7:0]: data output value this register sets the data output value for th e individual pins in th e port mapped by "vpctrla - virtual port-map control register a" or "vpc trlb - virtual port-map control register b". when a port is mapped as virtual, accessing this register is identical to accessing the actual out register for the port. 11.15.3 in - data input value ? bit 7:0 - in[7:0]: data input value this register shows the value present on the pins if the digital input buffer is enabled. the config- uration of "vpctrla - virtual port-map control register a" or "vpctrlb - virtual port-map control register b" decides the value in the regi ster. when a port is mapped as virtual, access- ing this register is identical to accessing the actual in register for the port. bit 76543210 +0x00 dir[7:0] dir read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x01 out[7:0] out read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x02 in[7:0] in read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000
119 8210b?avr?04/10 xmega d 11.15.4 intflags - interrupt flag register ? bit 7:2 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 1:0 - intnif: interrupt n flag the intnif flag is set when a pin change according to the pin's input sense configuration occurs, and the pin is set as source for port interrupt n. writing a one to this flag's bit location will clear the flag. for enabling and executing the inte rrupt refer to the interrupt level description. the configuration of "vpctrla - virtual port-ma p control register a" or "vpctrlb - virtual port-map control register b" decides which the flags mapped. when a port is mapped as vir- tual, accessing this register is identical to acce ssing the actual intflags register for the port. bit 76543210 +0x03 ? ? ? ? ? ? int1if int0if intflags read/writerrrrrrr/wr/w initial value00000000
120 8210b?avr?04/10 xmega d 11.16 register summary ? ports 11.17 register summary ? port configuration 11.18 register summary ? virtual ports 11.19 interrupt vector summary - ports address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 dir dir[7:0] 110 +0x01 dirset dirset[7:0] 110 +0x02 dirclr dirclr[7:0] 110 +0x03 dirtgl dirtgl[7:0] 111 +0x04 out out[7:0] 111 +0x05 outset outset[7:0] 111 +0x06 outclr outclr[7:0] 111 +0x07 outtgl outtgl[7:0] 112 +0x08 in in[7:0] 112 +0x09 intctrl ? ? ? ? int1lvl[1:0] int0lvl[1:0] 112 +0x0a int0mask int0msk[7:0] 113 +0x0b int1mask int1msk[7:0] 113 +0x0c intflags ? ? ? ? ? ? int1if int0if 113 +0x0d reserved ? ? ? ? ? ? ? ? +0x0e reserved ? ? ? ? ? ? ? ? +0x0f reserved ? ? ? ? ? ? ? ? +0x10 pin0ctrl ? inven opc[2:0] isc[2:0] 114 +0x11 pin1ctrl ? inven opc[2:0] isc[2:0] 114 +0x12 pin2ctrl ? inven opc[2:0] isc[2:0] 114 +0x13 pin3ctrl ? inven opc[2:0] isc[2:0] 114 +0x14 pin4ctrl ? inven opc[2:0] isc[2:0] 114 +0x15 pin5ctrl ? inven opc[2:0] isc[2:0] 114 +0x16 pin6ctrl ? inven opc[2:0] isc[2:0] 114 +0x17 pin7ctrl ? inven opc[2:0] isc[2:0] 114 +0x18 reserved ? ? ? ? ? ? ? ? +0x19 reserved ? ? ? ? ? ? ? ? +0x1a reserved ? ? ? ? ? ? ? ? +0x1b reserved ? ? ? ? ? ? ? ? +0x1c reserved ? ? ? ? ? ? ? ? +0x1d reserved ? ? ? ? ? ? ? ? +0x1e reserved ? ? ? ? ? ? ? ? +0x1f reserved ? ? ? ? ? ? ? ? address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 mpcmask mpcmask[7:0] 115 +0x01 reserved ? ? ? ? ? ? ? ? +0x02 vpctrla vp1map[3:0] vp0map[3:0] 115 +0x03 vpctrlb vp3map[3:0] vp2map[3:0] 116 +0x04 clkevout ? ? evout[1:0] ? ? clkout[1:0] 116 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 dir dir[7:0] 118 +0x01 out out[7:0] 118 +0x02 in in[7:0] 118 +0x03 intflags ? ? ? ? ? ? int1if int0if 119 table 11-10. ports interrupt vectors and their word offset address offset source interr upt description 0x00 int0_vect port interrupt vector 0 offset 0x02 int1_vect port interrupt vector 1 offset
121 8210b?avr?04/10 xmega d 12. tc - 16-bit timer/counter 12.1 features ? 16-bit timer/counter ? double buffered timer period setting ? up to 4 combined compare or capture (cc) ch annels (a, b, c, and d) ? all compare or capture channels are double buffered ? waveform generation: ? single slope pulse width modulation ? dual slope pulse width modulation ? frequency generation ? input capture: ? input capture with noise cancelling ? frequency capture ? pulse width capture ? 32-bit input capture direction control ? timer overflow and timer error interrupts / events ? one compare match or capture interrupt / event per cc channel ? hi-res- hi-resolu tion extension ? increases pwm/frq resolution by 2-bits (4x) ? awex - advanced waveform extension ? 4 dead-time insertion (dt) units with separate high- and low-side settings ? event controlled fault protection ? single channel multiple output operation ? pattern generation 12.2 overview xmega has a set of high-end and very flexible 16-bit timer/coun ters (tc). thei r basic capabili- ties include accurate program execution timing, frequency and waveform generation, event management, and time measurement of digital signals. the hi-resolution extension (hi-res) and advanced waveform extension (awex) can be used together with a timer/counter to ease implementation of more advanced and specialized frequency and waveform generation features. a block diagram of the 16-bit timer/counter with extensions and closely related peripheral mod- ules (in grey) is shown in figure 12-1 on page 122 .
122 8210b?avr?04/10 xmega d figure 12-1. 16-bit timer/counter and closely related peripheral the timer/counter consists of a base counter and a set of compare or capture (cc) channels. the base counter can be used to count clock cycles or events. it has direction control and period setting that can be used for timing. th e cc channels can be used together with the base counter to do compare match control, waveform generation (frq or pwm) or various input cap- ture operations. compare and capture cannot be done at the same time, i.e. a single timer/counter cannot simultaneously perform both waveform generation and capture operation. when used for com- pare operations, the cc channels is referred to as compare channels. when used for capture operations, the cc channels are referred to as capture channels. the timer/counter comes in two versions: timer/counter 0 that has four cc channels, and timer/counter 1 that has two cc channels. hence, all registers and register bits that are related to cc channel 3 and cc channel 4 w ill only exist in timer/counter 0. all timer/counter units are connected to the common peripheral clock prescaler, the event sys- tem, and their corresponding general purpose i/o port. some of the timer/counters will have extensions . the function of the timer/counter extensions can only be performed by these timers. the advanced waveform extension (awex) can be used for dead time insertion, pattern generation and fault protection. the awex extension is only available for timer/counter 0. waveform outputs from a timer/counter can optionally be passed through to a hi-resolution (hi-res) extension before forwarded to the port. this extension, running at up to four times the peripheral clock fr equency, to enhanc e the resolution by four times. all timer/counters will have the hi-res extention. awex compare/capture channel d compare/capture channel c compare/capture channel b compare/capture channel a waveform generation buffer comparator hi-res fault protection capture control base counter counter control logic timer period prescaler dti dead-time insertion pattern generation clk per4 ports event system clk per timer/counter
123 8210b?avr?04/10 xmega d 12.2.1 definitions the following definitions are used extensively throughout the timer/counter documentation: in general the term timer is used when the timer/counter clock control is handled by an internal source and the term counter is used if th e clock is given externally (from an event). 12.3 block diagram figure 12-2 on page 124 shows a detailed block diagram of the timer/counter without the extensions. table 12-1. timer/counter definitions name description bottom the counter reaches the bottom when it becomes zero. max the counter reaches maximum when it becomes all ones. top the counter reaches the top when it becomes equal to the highest value in the count sequence. the top value can be equal to the period (per) or the compare channel a (cca) register setting. this is selected by the waveform generator mode. update the timer/counter signalizes an update when it reaches bottom or top dependent of the waveform generator mode.
124 8210b?avr?04/10 xmega d figure 12-2. timer/counter block diagram the counter register (cnt), the period registers w/buffer (per and perbuf), and the com- pare and capture registers w/buffers (ccx and ccxbuf) are 16-bit registers. during normal operation the counter value is c ontinuously compared to zero and the period (per) value to determine whether the counter has reached top or bottom. the counter value is also compared to the ccx registers. these comparators can be used to generate interrupt requests. they also generate events for the event system. the waveform generator modes use the comparators to set the waveform period or pulse width. a prescaled peripheral clock and events from t he event system can be used for controlling the counter. the event system is also used as source to the input capture. combined with the quadrature decoding functionality in the event system qdec, the timer/counter can be used for high speed quadrature decoding. base counter bus bridge compare/capture (x = {a,b,c,d}) counter = ccx ccxbuf waveform generation v = perbuf per cnt v = 0 "count" "clear" "direction" "load" control logic evsel event select cksel clock select ovf/unf (int req.) errif (int req.) top "match" ccxif (int req.) control logic "capture" i/o data bus (16-bit) i/o data bus (8-bit) "ev" update bottom temp ctrl a b d ocx out c e intctrl a b g intflags
125 8210b?avr?04/10 xmega d 12.4 clock and event sources the timer/counter can be clocked from the peripheral clock (clk per ) and from the event sys- tem, and figure 12-3 shows the clock and event selection logic. figure 12-3. clock and event selection the peripheral clock is fed into the common prescaler (common for all timer/counters in a device). a selection of the prescaler outputs is di rectly available for the timer/counter. in addi- tion the whole range from 1 to 2 15 times prescaling is available through the event system. each timer/counter has separate clock selection (clksel), to select on e of the prescaler out- puts directly or an event channel as the counter (cnt) input. this is referred to as normal operation for the counter, for details refer to ?normal operation? on page 127 . by using the event system, any event source such as an external clock signal on any i/o pin can be used as clock input. in addition the timer/counter can be controlled via the event system. the event selection (evsel) and event action (evact) settings can be used to trigger an even t action from one or more events. this is referred to as event action controlled operation for the counter, for details refer to ?event action controlled operation? on page 127 . when event action controlled opera- tion is used, the clock selection must be set to us an event channel as the counter input. by default no clock input is selected and the timer/counter is not running (off state). 12.5 double buffering the period register and the cc registers are all double buffered. each buffer registers have an associated buffer valid (bv) flag, which indicate that the buffer contains a valid, i.e. a new value that is to be copied into the belonging period or compare register. for the period register and for the cc channels when used for compare operation, the buffer valid flag is set when data is writ- ten to the buffer register and cleared on update condition. this is shown for a compare register in figure 12-4 on page 126 . clk per / 2 {0,...,15} clksel cnt evact clk / {1,2,4,8,64,256,1024} common prescaler clk per event channels (encoding) event system evsel events control logic
126 8210b?avr?04/10 xmega d figure 12-4. period and compare double buffering when the cc channels is used for capture oper ation a similar double buffering mechanism is used, but the buffer valid flag is se t on the capture event as shown in figure 12-5 . for capture the buffer and the corresponding ccx register acts like a fifo. when the cc register is empty or read, any contents in the buffer is passed to the cc register. the buffer valid flag is passed to the ccx interrupt flag (if) which is them set and the optional interrupt is generated. figure 12-5. capture double buffering both the ccx and ccxbuf registers are available in the i/o register address map. this allows initialization and bypassing of the buffer register, and the double buffering feature. bv ccxbuf ccx update en i/o bus (16-bit) en "write enable" "data" = cnt "match" bv i/o bus (16-bit) "capture" if cnt ccxbuf ccx en en "int request"
127 8210b?avr?04/10 xmega d 12.6 counter operation dependent of the mode of operation, the counter is cleared, reloaded, incremented, or decre- mented at each timer/counter clock input. 12.6.1 normal operation in normal operation the counter will count in the direction set by the direction (dir) bit for each clock until it reaches top or bottom. w hen top is reached when up-counting, the counter will be set to zero when the next clock is gi ven. when down-counting the counter is reloaded with period register value when bottom is reached. figure 12-6. normal mode of operation as shown in figure 12-6 changing the counter value while the counter is running is possible. the write access has higher priority than count, clear, or reload and will be immediate. the direction of the counter can also be changed during normal operation. normal operation must be used when using the counter as timer base for the capture channels. 12.6.2 event action controlled operation the event selection and event action settings c an be used to control the counter from the event system. for the counter the event actions can be selected to: ? event system controlled up/down counting. ? event system controlled quadrature decode counting. 12.6.3 32-bit operation two timer/counters can be used together to enabl e 32-bit counter operation. by using two timer/counters the overflow event from one ti mer/counter (least significant timer) can be routed via the event system and used as clock input for another timer/counter (most significant timer). 12.6.4 changing the period the counter period is changed by writing a new top value to the period register. if double buffering is not used, any period update is immediate as shown in figure 12-7 on page 128 . cnt bot max "update" top cnt written dir
128 8210b?avr?04/10 xmega d figure 12-7. changing the period without buffering when double buffering is used, the buffer can be written at any time, but the period register is always updated on the ?update? condition as shown in figure 12-8 . this prevents wraparound and generation of odd waveforms. figure 12-8. changing period using buffering 12.7 capture channel the cc channels can be used as capture channel to capture external events and give them a time-stamp indicating time of occurrence. to use capture the counter must be set in normal operation. events are used to trigger the capture, i.e any events from the event system including pin change from any pin can trigger a capture operation. the event source select setting, selects the event channel that will trigge r cc channel a, and the followi ng event channels will then trig- ger events on the following cc channels if configured. for instance setting the event source select to event channel 2 will result in cc channel a being connected to event channel 2, cc channel b to event channel 3 and so on. cnt max new top written to per that is higher than current cnt counter wraparound new top written to per that is lower than current cnt "update" "write" bot cnt max new period written to perbuf that is higher than current cnt new period written to perbuf that is lower than current cnt "update" "write" new per is updated with perbuf value. bot
129 8210b?avr?04/10 xmega d event source selection for capture operation the event action setting in the timer/counter will determine the type of c apture that is done. the cc channel to use must be enabled individually before capture can be done. when the cap- ture condition occu r, the timer/counter will time-stamp the event by copying the current value in the count register into the enabled cc channel register. when an i/o pin is used as event source for the capture, the pin must be configured for edge sensing. for details on sense configuration on i/o pins, refer to ?input sense configuration? on page 106 . if the period register value is set lower than 0x8000, the polarity of the i/o pin edge will be stored in the most significant bit (msb) of the capture register after a capture. if the msb of the capture register is zero, a falling edge generated the capture. if the msb is one, a rising edge generated the capture. three different types of capture are available. 12.7.1 input capture selecting the input capture event action, makes the enabled capture channel perform an input capture on any event. the interrupt flags will be set and indicate that there is a valid capture result in the corresponding cc register. equally t he buffer valid flags indicates valid data in the buffer registers. refer to ?double buffering? on page 125 for more details on capture double buffering. the counter will continuously co unt for bottom to top, then restart on bottom as shown in figure 12-9 . the figure also shows four capture events for one capture channel. figure 12-9. input capture timing event system ch0mux ch1mux ch7mux rotate event channel 7 event source selection cca capture ccb capture ccc capture ccd capture event channel 0 event channel 1 events cnt top bot capture 0 capture 1 capture 2 capture 3
130 8210b?avr?04/10 xmega d 12.7.2 frequency capture selecting the frequency capture event action, makes the enabled capture channel perform a input capture and restart on any event. this enables timer/counter to use capture to measure the period or frequency of a signal directly. the capture result will be the time, t, from the previ- ous timer/counter restart and until the event occurred. this can be used to calculate the frequency, f, of the signal: figure 12-10 on page 130 shows an example where the period is measured twice for an exter- nal signal. figure 12-10. frequency capture of an external signal since all capture channels uses the same c ounter (cnt), only one capture channels must be enabled at a time. if two captur e channels are used with diff erent source, th e counter will be restarted on positive edge events from both input sources, and the result from the input capture will have no meaning. 12.7.3 pulse-width capture selecting the pulse-width measure event action makes the enabled compare channel perform the input capture ac tion on falling edge events and the rest art action on rising edge events. the counter will then start at zero at every star t of a pulse and the input capture will be performed at the end of the pulse. the event source must be an i/o pin and the sense configuration for the pin must be set up to generate an event on both edges. figure 12-11 on page 131 shows and exam- ple where the pulse width is measured twice for an external signal. f 1 t -- - = period (t) external signal events cnt max bot "capture"
131 8210b?avr?04/10 xmega d figure 12-11. pulse-width capture of external signal. 12.7.4 32-bit input capture two timer/counters can be used together to enable true 32-bit input capture. in a typical 32-bit input capture setup the overflow event of the least significant timer is connected via the event system and used as clock input for the most significant timer. since all events are pipe lined, the most significant timer w ill be updated one peripheral clock period after an overflow occurs for the least significant timer. to compensate for this delay the capture event for the most significant timer must be equally delayed by setting the event delay bit for this timer. 12.7.5 capture overflow the timer/counter can detect buffer overflow on any of the input capture channels. in the case where both the buffer valid flag and capture interrupt flag are set, and a new capture event is detected there is nowhere to store the new time-s tamp. if a buffer overflow is detected the new value is rejected, the error interrupt flag is set and the optional interrupt is generated. 12.8 compare channel each compare channel continuously compares the counter value (cnt) with the ccx register. if cnt equals ccx the comparator signals a match. the match will set the cc channel's interrupt flag at the next timer clock cycle, and the event and optional interrupt is generated. the compare buffer register provides double buffer capability equivalent to the period buffer. the double buffering synchronizes the update of the ccx register with the buffer value to either the top or bottom of the counting sequence according to the update condition signal from the timer/counter control logic. the synchronization prevents the occurrence of odd-length, non-symmetrical pwm/frq pulses, thereby making the output glitch-free. pulsewitdh (t p ) external signal events cnt max bot "capture"
132 8210b?avr?04/10 xmega d 12.8.1 waveform generation the compare channels can be used for waveform generation on the corresponding port pins. to make the waveform visible on the connected port pin, the following requirements must be fulfilled: 1. a waveform generation mode must be selected. 2. event actions must be disabled. 3. the cc channels to be used must be enabl ed. this will override the corresponding port pin output register. 4. the direction for the associated port pin must be set to output. inverted waveform output can be achieved by setting the invert output bit for the port pin. 12.8.2 frequency (frq) waveform generation for frequency generation the period time (t) is controlled by the cca register instead of per, which in this case is not in use. the waveform generation (wg) output is toggled on each com- pare match between the cnt and cca registers as shown in figure 12-12 on page 132 . figure 12-12. frequency waveform generation the waveform generated will have a maximum frequency of half of the peripher al clock fre- quency (f per ) when cca is set to zero (0x0000). this also applies when using the hi-res extension since this only increase the resolution and not the frequency. the waveform fre- quency (f frq )is defined by the following equation: where n represents the prescaler divider used (1, 2, 4, 8, 64, 256, 1024, or event channel n). 12.8.3 single slope pwm generation for single slope pwm generation, the period (t) is controlled by the per, while ccx registers control the duty cycle of the wg output. figure 12-13 shows how the counte r counts from bot- tom to top then restarts from bottom. the waveform generator (wg) output is set on the compare match between the cnt and ccx registers, and cleared at top. cnt max "update" top cnt written direction change period (t) bot wg output f frq f per 2 n cca+1 () ------------------------------- - =
133 8210b?avr?04/10 xmega d figure 12-13. single slope pulse width modulation the per register defines the pwm resolution. the minimum resolution is 2-bit (per=0x0003), and maximum resolution is 16-bit (per=max). the following equation can be used for calculat e the exact resolution for single-slope pwm (r pwm_ss ): the single slow pwm frequency (f pwm_ss ) depends on the period setting (per) and the periph- eral clock frequency (f per ), and can be calculated by the following equation: where n represents the prescaler divider used (1, 2, 4, 8, 64, 256, 1024, or event channel n). 12.8.4 dual slope pwm for dual slope pwm generation, the period (t) is controlled by the per, while ccx registers control the duty cycle of the wg output. figure 12-14 shows how for dual slope pwm the coun- ter counts repeatedly from bottom to top, and then from top to bottom. the wg output is. the waveform generator output is set on bottom, cleared on compare match when upcounting and set on compare match when down counting. cnt max top period (t) "match" bot wg output ccx=bot ccx ccx=top "update" r pwm_ss per 1 + () log 2 () log ----------------------------------- = f pwm_ss f per n per 1 + () ------------------------------ - =
134 8210b?avr?04/10 xmega d figure 12-14. dual-slope pulse width modulation using dual-slope pwm result in a lower maximum operation frequency compared to the single- slope pwm operation. the period register (per) defines the pwm re solution. the minimum resolution is 2-bit (per=0x0003), and maximum resolution is 16-bit (per=max). the following equation can be used for calculate the exact resolution for dual-slope pwm (r pwm_ds ): the pwm frequency depends on the period setting (per) and the peripheral clock frequency (f per ), and can be calculated by the following equation: n represents the prescaler divider used (1, 2, 4, 8, 64, 256, 1024, or event channel n). 12.8.5 port override for waveform generation to make the waveform generation available on the port pins the corresponding port pin direction must be set as output. the timer/counter will over ride the port pin values when the cc channel is enabled (ccenx) and a waveform generation mode is selected. figure 12-15 on page 135 shows the port override for timer/counter 0 and 1. for timer/counter 1, cc channel a to d will override port pin 0 to 3 output value (out xn) on the corresponding port pin (pxn). for timer/counter 1, cc channel a and b will overri de port pin 4 and 5. enabling inverted i/o on the port pin (invenxn) inverts the corresponding wg output. cnt max top period (t) bot wg output ccx=bot ccx ccx=top "match" "update" r pwm_ds per 1 + () log 2 () log ----------------------------------- = f pwm_ds f per 2 n per ------------------- - =
135 8210b?avr?04/10 xmega d figure 12-15. port override for timer/counter 0 and 1 12.9 interrupts and events the t/c can generate both interrupts and events. the counter can generate an interrupt on overflow/underflow, and each cc channel has a separate interrupt that is used for compare or capture. in addition the t/c can generate an error interrupt if any of the cc channels is used for capture and a buffer overflow condition occurs on a capture channel. event will be generated for all conditi ons that can generate interrupts. for de tails on event gen- eration and available events refer to ?event system? on page 44 . outx0 ccena invenx0 outx1 ccenb invenx1 px0 px1 oc0a oc0b outx2 ccenc invenx2 outx3 ccend invenx3 px2 px3 oc0c oc0d outx4 ccena invenx4 outx5 ccenb invenx5 px4 px5 oc1a oc1b wg 0a wg 0b wg 0c wg 0d wg 1a wg 1b
136 8210b?avr?04/10 xmega d 12.10 timer/counter commands a set of commands can be given to the timer/co unter by software to immediately change the state of the module. these commands give direct control of the update, restart, and reset signals. an update command has the same effect as when an update condition occurs. the update com- mand is ignored if the lock update bit is set. the software can force a restart of the current waveform period by issuing a restart command. in this case the counter, direction, and all compare outputs are set to zero. a reset command will set all timer/ counter registers to their init ial values. a reset can only be given when the timer/counter is not running (off).
137 8210b?avr?04/10 xmega d 12.11 register description 12.11.1 ctrla - control register a ? bit 7:4 - reserved bits these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 3:0 - clksel[3:0]: clock select these bits select clock source for the timer/counter according to table 12-2 . clksel=0001 must be set to ensure a correct output from the waveform generator when the hi-res extension is enabled. 12.11.2 ctrlb - control register b ? bit 7:4 ? ccxen: compare or capture enable setting these bits in frq or pwm waveform gener ation mode of operatio n will override of the port output register for the corresponding ocn output pin. when input capture operation is selected the ccxen bits enables the capture operation for the corresponding cc channel. bit 76543210 +0x00 ? ? ? ? clksel[3:0] ctrla read/write r r r r r/w r/w r/w r/w initial value00000000 table 12-2. clock select clksel[3:0] group configuration description 0000 off none (i.e, timer/ counter in ?off? state) 0001 div1 prescaler: clk 0010 div2 prescaler: clk/2 0011 div4 prescaler: clk/4 0100 div8 prescaler: clk/8 0101 div64 prescaler: clk/64 0110 div256 prescaler: clk/256 0111 div1024 prescaler: clk/1024 1xxx evchn event channel n, n= [0,...,7] bit 76543210 +0x01 ccden cccen ccben ccaen ? wgmode[2:0] ctrlb read/write r/w r/w r/w r/w r r/w r/w r/w initial value 0 0 0 0 0 0 0 0
138 8210b?avr?04/10 xmega d ? bit 3 ? reserved this bit is unused and reserved fo r future use. for comp atibility with future devices, always write this bit to zero when this register is written. ? bit 2:0 ? wgmode[2:0]: waveform generation mode these bits select the waveform generation mode, and control the counting sequence of the counter, the top value, the update condition, the interrupt/event condition, and type of wave- form that is generated, according to table 12-3 on page 138 . no waveform generation is performed in normal mode of operation. for all other modes the result from the waveform generator will only be directed to the port pins if the corresponding ccxen bit has been set to enable this. the port pin direction must be set as output. 12.11.3 ctrlc - control register c ? bit 7:4 ? reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 3:0 ? cmpx: compare output value n these bits allow direct access to the waveform generator's output compare value when the timer/counter is set in ?off? state. this is used to set or clear the wg output value when the timer/counter is not running. table 12-3. timer waveform generation mode wgmode[2:0] group configuration mode of operation top update ovfif/event 000 normal normal per top top 001 frq frq cca top top 010 reserved - - - 011 ss single slope pwm per bottom bottom 100 reserved - - - 101 ds_t dual slope pwm per bottom top 110 ds_tb dual slope pwm per bottom top and bottom 111 ds_b dual slope pwm per bottom bottom bit 76543210 +0x02 ? ? ? ? cmpd cmpc cmpb cmpa ctrlc read/write r r r r r/w r/w r/w r/w initial value00000000
139 8210b?avr?04/10 xmega d 12.11.4 ctrld - control register d ? bit 7:5 ? evact[2:0]: event action these bits define the event action the ti mer will perform on an event according to table 12-4 on page 139 . the evsel setting will decide which event source or sources that have the control in this case. selecting the any of the capture event acti on changes the behavior of the ccx registers and related status and control bits to be used as fo r capture. the er ror status flag (errif) will in this configuration indicate a buffer overflow. ? bit 4 ? evdly: timer delay event when this bit is set, the selected event source is delayed by one peripheral clock cycle. this fea- ture is intended for 32-bit input capture operati on. adding the event delay is necessary for compensating for the carry propagation delay th at is inserted when cascading two counters via the event system. ? bit 3:0 ? evsel[3:0]:ti mer event source select these bits select the event channel source for the timer/counter. for the selected event chan- nel to have any effect the event action bits (evact) must be set acco rding to table 12-5 . when the event action is set to capt ure operation, the selected even t channel n will be the event chan- nel source for cc channel a, and event channel (n+1)%8, (n +2)%8 and (n+3)%8 will be the event channel source for cc channel b, c and d. bit 76543210 +0x03 evact[2:0] evdly evsel[3:0] ctrld read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 table 12-4. timer event action selection evact[2:0] group configuration event action 000 off none 001 capt input capture 010 updown externally controlled up/ down count 011 qdec quadrature decode 100 restart restart waveform period 101 frq frequency capture 110 pw pulse width capture 111 reserved
140 8210b?avr?04/10 xmega d 12.11.5 ctrle - control register e ? bit 7:1 ? reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 0 - bytem: byte mode: enabling the byte mode, sets the timer/counter in byte (8-bit) mode. setting this bit will disable the update of the temporary register (temp) when any of the 16-bit timer/counter registers are accessed. in addition th e upper byte of the counter (cnt) r egister will be set to zero after each counter clock. 12.11.6 intctrla - interrupt enable register a ? bit 7:4 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. table 12-5. timer event source selection evsel[3:0] group configuration event source 0000 off none 0001 reserved 0010 reserved 0011 reserved 0100 reserved 0101 reserved 0110 reserved 0111 reserved 1xxx chn event channel n, n={0,...,3} bit 76543210 +0x04 ? ? ? ? ? ? ? bytem ctrle read/writerrrrrrrr/w initial value00000000 bit 76543210 +0x06 ? ? ? ? errintlvl[1:0] ovfintlvl[1:0] intctrla read/writerrrrr/wr/wr/wr/w initial value00000000
141 8210b?avr?04/10 xmega d ? bit 3:2 - errintlvl[1:0]:timer error interrupt level these bits enable the timer error interrupt and select the interrupt level as described in ?inter- rupts and programmable multi-level interrupt controller? on page 95 . ? bit 1:0 - ovfintlvl[1:0]:timer overflow/underflow interrupt level these bits enable the timer overflow/underflow interrupt and select the interrupt level as described in ?interrupts and programmable multi-level interrupt controller? on page 95 . 12.11.7 intctrlb - interrupt enable register b ? bit 7:0 - ccxintlvl[1:0] - compare or capture x interrupt level: these bits enable the timer compare or capture interrupt and select the interrupt level as described in ?interrupts and programmable multi-level interrupt controller? on page 95 . 12.11.8 ctrlfclr/ctrlfset - co ntrol register f clear/set this register is mapped into two i/o memory locations, one for clearing (ctrlxclr) and one for setting the register bits (ctrlxset) when writte n. both memory locations yield the same result when read. the individual status bit can be set by writing a one to its bit location in ctrlxset, and cleared by writing a one to its bit location in ctrlxclr. this each bit to be set or cleared without using of a read-modify-write operation on a single register. ? bit 7:4 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 3:2 - cmd[1:0]: timer/counter command these command bits can be used for software control of update, restart, and reset of the timer/counter. the command bits are always read as zero. bit 76543210 +0x07 ccdintlvl[1:0] cccintlvl[1:0] ccbintlvl[1:0] ccaintlvl[1:0] intctrlb read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x08 ? ? ? ? cmd[1:0] lupd dir ctrlfclr read/writerrrrrrr/wr/w initial value00000000 bit 76543210 +0x09 ? ? ? ? cmd[1:0] lupd dir ctrlfset read/write r r r r r/w r/w r/w r/w initial value00000000
142 8210b?avr?04/10 xmega d ? bit 1 - lupd: lock update: when this bit is set no update of the buffered registers is performed, even though an update condition has occurred. locking the update ensures that all buffers, including dti buffers, are valid before an update is performed. this bit has no effect when input capture operation is enabled. ? bit 0 - dir: counter direction: when zero, this bit indicates that the counter is counting up (incrementing). a one indicates that the counter is in down counting (decrementing) state. normally this bit is controlled in hardware by the waveform generation mode, or by event actions, but this bit can also be changed from software. 12.11.9 ctrlgclr/ctrlgset - c ontrol register g clear/set refer to section ?ctrlfclr/ctrlfset - control register f clear/set? on page 141 for infor- mation on how to access this type of status register. ? bit 7:5 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 4:1 - ccxbv: compare or capture x buffer valid these bits are set when a new value is written to the corresponding ccxbuf register. these bits are automatically cleared on an update condition. note that when input capture operation is used, this bit is set on capture event and cleared if the corresponding ccxif is cleared. ? bit 0 - perbv: period buffer valid this bit is set when a new value is written to the perbuf register. this bit is automatically cleared on an update condition. table 12-6. command selections cmd group configuration command action 00 none none 01 update force update 10 restart force restart 11 reset force hard reset (ignored if t/c is not in ?off?state) bit 76543210 +0x0a/ +0x0b ? ? ? ccdbv cccbv ccbbv ccabv perbv ctrlgclr/set read/write r r r r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
143 8210b?avr?04/10 xmega d 12.11.10 intflags - interrupt flag register ? bit 7:4 - ccxif: compare or capture channel x interrupt flag the compare or capture interrupt flag (ccxif) is set on a compare match or on an input cap- ture event on the corresponding cc channel. for all modes of operation except for capture the ccxif will be set when a compare match occurs between the count register (cnt) and the corresponding compare register (ccx). the ccxif is automatically cleared when the corresponding interrupt vector is executed. for input capture operat ion the ccxif will be set if the co rresponding compar e buffer contains valid data (i.e. when ccxbv is se t). the flag will be cleared when the ccx register is read. exe- cuting the interrupt vector will in this mode of operation not clear the flag. the flag can also be cleared by writing a one to its bit location. ? bit 3:2 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 1 - errif: error interrupt flag the errif is set on multiple occasions depending on mode of operation. in frq or pwm waveform generation mode of ope ration the errif is set on a fault detect con- dition from the fault protection feature in the awex extention. for timer/counters which do not have the awex extention available, this flag is never set in frq or pwm waveform generation mode. for capture operation the errif is set if a buffer overflow occurs on any of the cc channels. for event controlled qdec operation the errif is set when an incorrect index signal is given. the errif is automatically cleared when the corresponding interrupt vector is executed. the flag can also be cleared by writing a one to its bit location. ? bit 0 - ovfif: overflow/underflow interrupt flag the ovfif is set either on a top (overflow) or bottom (underflow) condition depending on the wgmode setting. the ovfif is automatically cleared when the corresponding interrupt vector is executed. the flag can also be cl eared by writing a one to its bit location. 12.11.11 temp - temporary register for 16-bit access the temp register is used for single cycle 16-bit access to t he 16-bit timer/counter registers from the cpu. there is one common temp register for all the 16-bit timer/counter registers. bit 76543210 +0x0c ccdif cccif ccbif ccaif ? ? errif ovfif intflags read/write r/w r/w r/w r/w r r r/w r/w initial value 0 0 0 0 0 0 0 0
144 8210b?avr?04/10 xmega d for more details refer to ?accessing 16-bits registers? on page 12 . 12.11.12 cnth - counter register h the cnth and cntl register pair represents t he 16-bit value cnt. cnt contains the 16-bit counter value in the timer/counter. the cpu wr ite access has priority over count, clear, or reload of the counter. for more details on reading and writing 16-bit register refer to ?accessing 16-bits registers? on page 12 . ? bit 7:0 - cnt[15:8] these bits holds the 8 msb of the 16-bit counter register. 12.11.13 cntl - counter register l ? bit 7:0 - cnt[7:0] these bits holds the 8 lsb of the 16-bit counter register. 12.11.14 perh - period register h the perh and perl register pair represents t he 16-bit value per. per contains the 16-bit top value in the timer/counter. ? bit 7:0 - per[15:8] these bits holds the 8 msb of the 16-bit period register. bit 76543210 +0x0f temp[7:0] temp read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x21 cnt[15:8] cnth read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x20 cnt[7:0] cntl read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x27 per[15:8] perh read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value11111111
145 8210b?avr?04/10 xmega d 12.11.15 perl - period register l ? bit 7:0 - per[7:0] these bits holds the 8 lsb of the 16-bit period register. 12.11.16 ccxh - compare or capture register n h the ccxh and ccxl register pair represents the 16-bit value ccx. these 16-bit registers have two functions dependent of mode of operation. for capture opera- tion these registers constitute the second buf fer level and access point for the cpu. for compare operation these registers are all continuously compared to the counter value. normally the outputs form the comparators are then used for generating waveforms. ccx are updated with the buffer value from the corresponding ccxbuf register when an update condition occurs. ? bit 7:0 - ccx[15:8] these bits holds the 8 msb of the 16-bit compare or capture register. 12.11.17 ccxl - compare or capture register n l ? bit 7:0 - ccx[7:0] these bits holds the 8 lsb of the 16-bit compare or capture register. 12.11.18 perbufh - timer/counter period buffer h the perbufh and perbufl register pair repres ents the 16-bit value perbuf. this 16-bit register serves as the buffer for the period re gister (per). accessing this register using cpu will affect the perbufv flag. bit 76543210 +0x26 per[7:0] perl read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 1 1 1 1 1 1 1 1 bit 76543210 ccx[15:8] ccxh read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 ccx[7:0] ccxl read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000
146 8210b?avr?04/10 xmega d ? bit 7:0 - perbuf[15:8] these bits holds the 8 msb of the 16-bit period buffer register. 12.11.19 perbufl - timer/counter period buffer l ? bit 7:0 - perbuf[7:0] these bits holds the 8 lsb of the 16-bit period buffer register. 12.11.20 ccxbufh - compare or capture x buffer register h the ccxbufh and ccxbufl register pair represents the 16-bit value ccxbuf. these 16-bit registers serve as the buffer for the associated compare or capture registers (ccx). accessing any of these register us ing cpu will affect the corresponding ccxbv status bit. ? bit 7:0 - ccxbuf[15:8] these bits holds the 8 msb of the 16-bit compare or capture buffer register. 12.11.21 ccxbufl - compare or capture x buffer register l ? bit 7:0 - ccxbuf[7:0] these bits holds the 8 lsb of the 16-bit compare or capture buffer register. bit 76543210 +0x37 perbuf[15:8] perbufh read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 1 1 1 1 1 1 1 1 bit 76543210 +0x36 perbuf[7:0] perbufl read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value11111111 bit 76543210 ccxbuf[15:8] ccxbufh read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 ccxbufx[7:0] ccxbufl read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000
147 8210b?avr?04/10 xmega d 12.12 register summary 12.13 interrupt vector summary note: 1. only available on timer/counter with 4 compare or capture channels 16-bit. address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 ctrla ? ? ? ? clksel[3:0] 137 +0x01 ctrlb ccden cccen ccben ccaen ? wgmode[2:0] 137 +0x02 ctrlc ? ? ? ? cpmd cpmc cpmb cpma 138 +0x03 ctrld evact[2:0] evdly evsel[3:0] 139 +0x04 ctrle ? ? ? ? ? ? ?bytem140 +0x05 reserved ? ? ? ? ? ? ? ? +0x06 intctrla ? ? ? ? errintlvl[1:0] ovintlvl[1:0] 140 +0x07 intctrlb cccintlvl[1:0] cccintlvl[ 1:0] ccbintlvl[1:0] ccaintlvl[1:0] 140 +0x08 ctrlfclr ? ? ? ? cmd[1:0] lupd dir 141 +0x09 ctrlfset ? ? ? ? cmd[1:0] lupd dir 142 +0x0a ctrlgclr ? ? ? ccdbv cccbv ccbb v ccabv perbv 142 +0x0b ctrlgset ? ? ? ccdbv cccbv ccbb v ccabv perbv 142 +0x0c intflags ccdif cccif ccbif ccaif ? ? errif ovfif 143 +0x0d reserved ? ? ? ? ? ? ? ? +0x0e reserved ? ? ? ? ? ? ? ? +0x0f temp temp[7:0] 143 +0x10 to +0x1f reserved ? ? ? ? ? ? ? ? +0x20 cntl cnt[7:0] 144 +0x21 cnth cnt[15:8] 144 +0x22 to +0x25 reserved ? ? ? ? ? ? ? ? +0x26 perl per[7:0] 145 +0x27 perh per[8:15] 144 +0x28 ccal cca[7:0] 145 +0x29 ccah cca[15:8] 145 +0x2a ccbl ccb[7:0] 145 +0x2b ccbh ccb[15:8] 145 +0x2c cccl ccc[7:0] 145 +0x02d ccch ccc[15:8] 145 +0x2e ccdl ccd[7:0] 145 +0x2f ccdh ccd[15:8] 145 +0x30 to +0x35 reserved ? ? ? ? ? ? ? ? +0x36 perbufl perbuf[7:0] 146 +0x37 perbufh perbuf[15:8] 145 +0x38 ccabufl ccabuf[7:0] 146 +0x39 ccabufh ccabuf[15:8] 146 +0x3a ccbbufl ccbbuf[7:0] 146 +0x3b ccbbufh ccbbuf[15:8] 146 +0x3c cccbufl cccbuf[7:0] 146 +0x3d cccbufh cccbuf[15:8] 146 +0x3e ccdbufl ccdbuf[7:0] 146 +0x3f ccdbufh ccdbuf[15:8] 146 table 12-7. timer/counter interrupt vectors and their word offset address offset source interrupt description 0x00 ovf_vect timer/counter overflow/underflow interrupt vector offset 0x02 err_vect timer/counter error interrupt vector offset 0x4 cca_vect timer/counter compare or capture channel a interrupt vector offset 0x6 ccb_vect timer/counter compare or capture channel b interrupt vector offset 0x8 ccc_vect (1) timer/counter compare or capture channel c interrupt vector offset 0x0a ccd_vect (1) timer/counter compare or capture channel d interrupt vector offset
148 8210b?avr?04/10 xmega d 13. hi-res - high r esolution extension 13.1 features ? increases waveform generator resolution by 4x (2 bits) ? supports frequency generation, and si ngle and dual-slope pwm operation ? supports dead-time insertion (awex) ? supports pattern generation (awex) 13.2 overview the high-resolution (hi-res) extension can be used to increase the reso lution of the waveform generation output from a timer/counter by four (two bits). it can be used during frequency and pwm generation, and also in combination with the corresponding awex. the hi-res extension uses the peripheral 4x clock. the system clock prescalers must be set up so the peripheral 4x clock frequency is four times higher than the peripheral and cpu clock frequency (see ?system clock selection and prescalers? on page 59 ) when the hi-res extension is enabled. figure 13-1. timer/counter operation wit h hi-res extension enabled the hi-res extension is implemented by letting the timer/counter run at 4x its normal speed. when hi-res extension is enabled , the counter will ignore its two lowest significant bits (lsb) and count by four for each peri pheral clock cycle. overflow/underflow and compare match of the 14 most significant bits (lsb) is done in the timer/counter. count and compare of the two lsb is then handled and compared in the hi-res extension running from the peripheral 4x clock. the two lsb of the period register must always be set to zero to ensure correct operation. if the count register is read, the two lsb will always be read as ze ro since the timer/counter run from the peripheral clock. the hi-res extension has narrow pulse deletion preventing output of any pulse shorter than one peripheral clock cycle, e.g. a compare va lue lower than foure will have no visible output. cnt[15:2] hires ccbufx[15:0] = = 0 "match" = per[15:2] 0 waveform generation top bottom time/counter ccx[15:2] [1:0] 2 2 2 0 awex fault protection dti dead-time insertion pattern generation clk per clk per4 pnx
149 8210b?avr?04/10 xmega d 13.3 register description 13.3.1 ctrla - hi-res control register a ? bit 7:2 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 1:0 - hren[1:0]: hi-resolution enable enables hi-resolution mode for a timer/counter according to table 13-1 . setting one or both hren bits will enable hi-resolution wave form generation output for the entire general purpose i/o port. this means that both timer/counters connected to the same port must enable hi-res if both are used for generating pwm or frq output on pins. 13.4 register summary bit 76543210 +0x00 ? ? ? ? ? ? hren[1:0] ctrla read/writerrrrrrr/wr/w initial value00000000 table 13-1. hi-resolution enable hren[1:0] hi-resolu tion enabled 00 none 01 timer/counter 0 10 timer/counter 1 11 both timer/counters address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 ctrla ? ? ? ? ? ? hren[1:0] 149
150 8210b?avr?04/10 xmega d 14. awex ? advanced waveform extension 14.1 features ? 4 dead-time insertion (dti) units (8-pin) ? 8-bit resolution ? separate high and low side dead-time setting ? double buffered dead-time ? halts timer during dead-time (optional) ? event controlled fault protection ? single channel multiple output operation (for bldc control) ? double buffered pattern generation ? the hi-resolution timer exte nsion increases pwm/frq r esolution by 2-bits (4x) 14.2 overview the advanced waveform extention (awex) provi des extra features to the timer/counter in waveform generation (wg) modes. the awex enables easy and robust implementation of advanced motor control (ac, bldc, sr, and stepper) and power control applications. figure 14-1. advanced waveform extention and closely related peripherals (grey) as shown in figure 14-1 on page 150 each of the waveform generator outputs from the timer/counter 0 are split into a complimentar y pair of outputs when any awex features is enabled. these output pairs go through a dead-time insertion (dti) unit that enables genera- tion of the non-inverted low side (ls) and inverted high side (hs) of the wg output with dead time insertion between ls and hs switching. the dti output will override the normal port value according to the port override setting. optionally the final output can be inverted by using the invert i/o (inven) bit setting for the port pin (pxn). portx timer/counter 0 awex wg channel a dti channel a wg channel b dti channel b wg channel c dti channel c wg channel d dti channel d port override pattern generation px0 px1 px2 px3 px4 px5 px6 px7 inven inven inven inven inven inven inven inven event system fault protection
151 8210b?avr?04/10 xmega d the pattern generation unit can be used to generate a synchronized bit pattern on the port it is connected to. in addition, the waveform generator output from the compare channel a can be distributed to and override all the port pins. when the pattern generator unit is enabled the dti unit is bypassed. the fault protection unit is connected to the even t system, enabling any event to trigger a fault condition that will disable the awex output. 14.3 port override common for all the timer/counter extensions is the port override logic. figure 14-2 on page 152 shows a schematic diagram of the port override logic. when the dead-time enable (dtienx) bit is set the timer/counter extension takes control over the pin pair for the corresponding channel. given this condition the output override enable (ooe) bits takes control over the ccxen. note that timer/coun ter 1 (tcx1) can still be used even when dti channels a, b, and d are enabled.
152 8210b?avr?04/10 xmega d figure 14-2. timer/counter extensions and port override logic portx0 ooe0 ccena dtiena invx0 portx1 ooe1 ccenb invx1 px0 px1 channel a dti ls hs oc0a oc0b oclsa ochsa wg 0a wg 0b wg 0a cwcm portx2 ooe2 ccenc dtienb invx2 portx3 ooe3 ccend invx3 px2 px3 channel b dti ls hs oc0c oc0d oclsb ochsb wg 0c wg 0d portx4 ooe4 ccena dtienc invx4 portx5 ooe5 ccenb invx5 px4 px5 channel c dti ls hs oc1a oc1b oclsc ochsc wg 1a wg 1b portx6 ooe6 dtiend invx6 portx7 ooe7 invx7 px6 px7 channel d dti ls hs oclsd ochsd wg 0b wg 0d wg 0c "0" "0"
153 8210b?avr?04/10 xmega d 14.4 dead time insertion the dead time insertion (dti) unit enables generation of ?off? time where both the non-inverted low side (ls) and inverted high side (hs) of the wg output is low. this ?off? time is called dead-time, and dead-time insertion ensure that the ls and hs does not switch simultaneously. the dti unit consists of four equal dead time generators, one for each of the capture or com- pare channel in timer/counter 0. figure 14-3 on page 153 shows the block diagram of one dead time generator. the dead time registers that define the number of peripheral clock cycles the dead time is going to last, are common for all four channels. the high side and low side can have independent dead time setting and the dead time registers are double buffered. figure 14-3. dead time generator block diagram as shown in figure 14-4 on page 154 , the 8-bit dead time counter (dti_cnt) is decremented by one for each peripheral clock cycle until it re aches zero. a non-zero co unter value will force both the low side and high side outputs into their ?off? state. when a change is detected on the wg output, the dead time counter is reloaded with the dtx register value according to the edge of the input. positive edge initiates a counter reload of the dtls register and a negative edge a reload of dths register. dead time generator edge detect v v dq = 0 dtlsbuf dtils dthsbuf dtihs wg output "dtls" (to port) "dths" (to port) counter ("dti_cnt") e load
154 8210b?avr?04/10 xmega d figure 14-4. dead time generator timing diagram 14.5 pattern generation the pattern generator extension reuses the dti registers to produce a synchronized bit pattern on the port it is connected to. in addition, the waveform generator output from cc channel a (cca)) can be distributed to and override all th e port pins. these features are primarily intended for handling the commutation sequence in bldc and stepper motor applications. figure 14-5. pattern generator block diagram a block diagram of the pattern generator is shown in figure 14-5 on page 154 . for each port pin where the correspo nding ooe bit is set the multiple xer will output the waveform from cca. as for all other types of the timer/counter double-buffered registers the register update is syn- chronized to the update condition set by the waveform generation mode. if the synchronization provided is not required by t he application, the application code can simply access the dtioe and port x registers directly. the pins direction must be set for any output from the pattern generator to be visible on the port. "dti_cnt" "wg output" "dtls" "dths" t dtils t dtihs t t p timer/counter 0 (tcx0) v v dtibls dtioe[7:0] dtibhs portx[7:0] cca wg output update en en 1 to 8 expand px[7:0]
155 8210b?avr?04/10 xmega d 14.6 fault protection the fault protection feature enables fast and deterministic action when a fault is detected. the fault protection is event controlled, thus any even t from the event system can be used to trigger a fault action. when the fault protection is enabled an incoming event from any of the selected event channel can trigger the event action. each event channel can be separately enabled as fault protection input, and the spec ified event channels will be ored together allowing multiple event sources top be used for fault protection at the same time. 14.6.1 fault actions two different even actions can be selected: ? the clear override enable action will clear th e output override enab le register (outoven) and disable the output override on all timer/counter outputs. the result is that the in the output will be as set by the port pin configuration. ? the direction clear action will clear the direction (dir) register in the associated port, setting all port pins as tri-stated inputs. when a fault is detected the fault detection flag is set, and the timer/counter?s error interrupt flag is set and the optional interrupt is generated. from the event occurs in one peripherals until the fault protection triggers the event action, there is maximum two peripheral clock cycles. the fault protec tion is fully independent of the cpu, but it requires the peripheral clock to run. 14.6.2 fault restore modes after a fault, that is when the fault condition is no longer active, it is selectable how the awex and timer/counter can return from fault state and restore with normal operation. two different modes are available: ? in latched mode the waveform out put will remain in the fault stat e until the faul t condition is no longer active and the fault detect flag has been cleared by software. when both of these conditions are met, the waveform output will retu rn to normal operation at the next update condition. ? in cycle-by-cycle mode the waveform output will remain in the fault state until the fault condition is no longer active. when this condition is met, the waveform output will return to normal operation at the next update condition. when entering fault state and the clear override enable action is selected, the outoven[7:0] bits are reassigned a value on the next update c ondition. in pattern generation mode the reg- ister is restored wit h the value in the dtlsbuf register. otherwise the register bits are restored according to the enabled dti channels. when entering fault state and direction clear action is select is set, corresponding dir[7:0] bits is restored with the value in the dtlsbuf register in pattern generation mode and for the pin pairs corresponding to enabled dti channels otherwise. the update condition used to restore the normal operation is the same update as in the timer/counter. 14.6.3 change protection to avoid unintentional changes in the fault protection setup all the control registers in the awex extension can be protected by writing the corr esponding lock bit advanced waveform extension
156 8210b?avr?04/10 xmega d lock register. for more details refer to ?io memory protection? on page 22 and ?awexlock ? advanced waveform extension lock register? on page 40 . when the lock bit is set, the control register a, the output override enable register and the fault dedec.tion event mask register cannot be changed. to avoid unintentional changes in the fault event setup it is possible to lock the event system channel configuration by writing the corres ponding event system lock register. for more details refer to ?io memory protection? on page 22 and ?evsyslock ? event system lock register? on page 40 . 14.6.4 on-chip debug when fault detection is enabled an ocd system receives a break request from the debugger, this will by default function as a fault sour ce. when an ocd break r equest is received, the awex and corresponding timer/counter will enter fa ult state and the specified fault action(s) will be performed. after the ocd exits from the break condition, normal operation will be started again. in cycle-by- cycle mode the waveform output will start on the fi rst update cond ition after exit from break, and in latched mode, the fault condition flag must be cleared in software before the output will be restored. this feature guarantees that the output waveform enters a safe state during break. it is possible to disable this feature. 14.7 register description 14.7.1 ctrl - control register ? bit 7:6 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 5 - pgm: pattern generation mode setting this bit enables the pattern generation mode if set. this will over ride the dti if enabled, and the pattern generation reuses the dead-time registers for storing the pattern. ? bit 4 - cwcm: common waveform channel mode if this bit is set cc channel a waveform output will be used as input fo r all the dead-time genera- tors. cc channel b, c, and d waveforms will be ignored. ? bit 3:0 - dticcxen: dead-time insertion ccx enable setting these bits enables the de ad time generator for the corr esponding cc channel. this will override the timer/counter waveform outputs. bit 7654 3 2 1 0 +0x00 ? ? pgm cwcm dticcden dti cccen dticcben dticcaen ctrl read/write r r r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
157 8210b?avr?04/10 xmega d 14.7.2 fdemask - fault detect event mask register ? bit 7:0 - fdevmask[7:0]: fault detect event mask these bits enables the corresponding event channel as fault condition input source. event from all event channels will be ored to gether allowing mult iple sources to be used for fault detection at the same time. when a fault is detected the fault detect flag fdf is set and the fault detect action (fdact) will be performed. 14.7.3 fdctrl - fault de tection control register ? bit 7:5 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 4 - fddbd: fault detection on debug break detection by default, when this bit is cleared and the fault protection is enabled, and ocd break request is treated as a fault. when this bit is set, an oc d break request will not tr igger a fault condition. ? bit 3 - reserved this bit is unused and reserved fo r future use. for comp atibility with future devices, always write this bit to zero when this register is written. ? bit 2- fdmode: fault detection restart mode this bit sets the fault protection restart mode. when this bit is cleared latched mode is use, and when this is set cycle-by-cycle mode is used. in latched mode the wave form output will remain in the fault state until the fault condition is no longer active and the fdf has been cleared by software. when both of these conditions are met, the waveform output will re turn to normal ope ration at the next update condition. in cycle-by-cycle mode the waveform output will rema in in the fault state un til the faul t condition is no longer active. when this condition is met, the waveform output will re turn to normal opera- tion at the next update condition . ? bit 1:0 - fdact[1:0]: fault detection action these bits define the action performed if a fault condition is detected, according to table 14-1 . bit 76543210 +0x02 fdevmask[7:0] fdemask read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x03 ? ? ? fddbd ? fdmode fdact[1:0] fdctrl read/write r r r r/w r r/w r/w r/w initial value00000000
158 8210b?avr?04/10 xmega d 14.7.4 status - status register ? bit 7:3 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 2 - fdf: fault detect flag this flag is set when a fault detect condition is detected, i.e. when an event is detected on one of the event channels enabled by the fdevmask. this flag is cleared by writing a one to its bit location. ? bit 1 - dthsbufv: dead-time high side buffer valid if this bit is set the correspondi ng dt buffer is written and contai ns valid data that will be copied into the dtls register on the update condition. if this bit is zero no action will be taken. the connected timer/counter?s lock update (lupd) flag also affects the update for dead time buffers. ? bit 0 - dtlsbufv: dead-time low side buffer valid if this bit is set the correspondi ng dt buffer is written and contai ns valid data that will be copied into the dths register on the up date condition. if this bit is zero no action will be taken. note that the connected timer/counter unit's lock update (lupd) flag also affects the update for dead time buffers. 14.7.5 dtboth - dead-time concurrent write to both sides table 14-1. fault actions fdact[1:0] group configuration description 00 none none (fault protection disabled) 01 clearoe clear all override enable (outoven) bits, i.e. disable the output override. 11 cleardir clear all direction (dir) bits, which correspond to enabled dti channel(s), i.e. tri-state the outputs bit 76543 2 1 0 +0x04 ? ? ? ? ? fdf dthsbufv dtlsbufv status read/write r r r r r r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x06 dtboth[7:0] dtboth read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000
159 8210b?avr?04/10 xmega d ? bit 7:0 - dtboth: dead-time both sides writing to this register will upda te both dths and dtls registers at the same time (i.e. at the same i/o write access). 14.7.6 dtbothbuf - dead-time concurrent write to both sides buffer ? bit 7:0 - dtbothbuf: dead-time both sides buffer writing to this memory loca tion will update both dthsbuf and dtlsbuf registers at the same time (i.e. at the same i/o write access). 14.7.7 dtls - dead-time low side register ? bit 7:0 - dtls: dead-time low side this register holds the number of peripheral clock cycles for the dead-time low side. 14.7.8 dths - dead-time high side register ? bit 7:0 - dths: dead-time high side this register holds the number of peripheral clock cycles for the dead-time high side. 14.7.9 dtlsbuf - dead-time low side buffer register ? bit 7:0 - dtlsbuf: dead-time low side buffer this register is the buffer for the dtls register. if double buffering is used, valid contents in this register is copied to the dtls register on an update condition. bit 76543210 +0x07 dtbothbuf[7:0] dtbothbuf read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x08 dtls[7:0] dtls read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x09 dths[7:0] dths read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x0a dtlsbuf[7:0] dtlsbuf read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000
160 8210b?avr?04/10 xmega d 14.7.10 dthsbuf - dead-time high side buffer register ? bit 7:0 - dthsbuf: dead-time high side buffer this register is the buffer for the dths register. if double buffering is used , valid contents in this register is copied to the dths register on an update condition. 14.7.11 outoven - output override enable register note: 1. can only be written if the fault detect flag (fdf) is zero. ? bit 7:0 - outoven[7:0]: output override enable these bits enable override of corresponding port output register (i.e. one-to-one bit relation to pin position). the port direction is not overridden bit 76543210 +0x0b dthsbuf[7:0] dthsbuf read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x0c outoven[7:0] outoven read/write r/w (1) r/w (1) r/w (1) r/w (1) r/w (1) r/w (1) r/w (1) r/w (1) initial value00000000
161 8210b?avr?04/10 xmega d 14.8 register summary address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 ctrl ? ? pgm cwcm dticdaen dticcc en dticcben dticcaen 156 +0x01 reserved ? ? ? ? ? ? ? ? +0x02 fdemask fdevmask[7:0] 157 +0x03 fdctrl ? ? ?fddbd ? fdmode fdact[1:0] 157 +0x04 status ? ? ? ? ? fdf dtbhsv dtblsv 158 +0x05 reserved ? ? ? ? ? ? ? ? +0x06 dtboth dtboth[7:0] 158 +0x07 dtbothbuf dtbothbuf[7:0] 159 +0x08 dtls dtls[7:0] 159 +0x09 dths dths[7:0] 159 +0x0a dtlsbuf dtlsbuf[7:0] 159 +0x0b dthsbuf dthsbuf[7:0] 159 +0x0c outoven outoven[7:0] 160
162 8210b?avr?04/10 xmega d 15. rtc - real time counter 15.1 features ? 16-bit resolution ? selectable clock reference ? 32.768 khz ? 1.024 khz ? programmable prescaler ? 1 compare register ? 1 period register ? clear timer on overflow ? optional interrupt/ event on overflow and compare match 15.2 overview the real time counter (rtc) is a 16-bit counter, counting reference clock cycles and giving an event and/or an interrupt request when it reaches a configurable compare and/or top value. the reference clock is typically generated from a high accuracy crystal of 32.768 khz, and the design is optimized for low power consumption. the rt c typically operate in low power sleep modes, keeping track of time and waking up the device at regular intervals. the rtc reference clock may be taken from an 32.768 khz or 1.024 khz input. both an external 32.768 khz crystal oscillator or the 32.768 khz inte rnal rc oscillator can be selected as clock source. for details on reference clock selection to the rtc refer to ?rtcctrl - rtc control register? on page 65 in the clock system section. the rtc has a programmable prescaler to scale down the reference clock before it reaches the counter. the rtc can generate both compare and overflow interrupt request and/or events. figure 15-1. real time counter overview. 10-bit prescaler 16-bit counter 16-bit period 16-bit compare = = overflow compare match 1.024 khz 32.768 khz
163 8210b?avr?04/10 xmega d 15.2.1 clock domains the rtc is asynchronous, meaning it operates from a different clock source and independently of the main system clock and its derivative clocks such as the peripheral clock. for control and count register updates it will take a number of rtc clock and/or peripheral clo ck cycles before an updated register value is available or until a configuration change has effect on the rtc. this synchronization time is described for each register. 15.2.2 interrupts and events the rtc can generate both interrupts and ev ents. the rtc will give a compare interrupt request and/or event when the counter value equals the compare register value. the rtc will give an overflow interrupt request and/or even t when the counter value equals the period regis- ter value. the overflow will also reset the counter value to zero. due to the asynchronous clock domains event will only will only be generated for every third overflow or compare if the period register is zero. if the period register is one, events will only be generated for every second overflow or compare. when the period register is equal to or above two, events will trigger at ev ery overflow or compare just as the interrupt request. 15.3 register description 15.3.1 ctrl - real time counter control register ? bits 7:3 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bits 2:0 - prescaler[2:0]: rtc clock prescaling factor these bits define the prescaling factor for the rtc clock before the counter according to table 15-1 on page 163 . bit 76543210 +0x00 ? ? ? ? ? prescaler[2:0] ctrl read/write r r r r r r/w r/w r/w initial value 0 0 0 0 0 0 0 0 table 15-1. real time counter clock prescaling factor prescaler[2:0] group configuration rtc clock prescaling 000 off no clock source, rtc stopped 001 div1 rtc clock / 1 (no prescaling) 010 div2 rtc clock / 2 011 div8 rtc clock / 8 100 div16 rtc clock / 16 101 div64 rtc clock / 64 110 div256 rtc clock / 256 111 div1024 rtc clock / 1024
164 8210b?avr?04/10 xmega d 15.3.2 status - real time counter status register ? bits 7:1 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 0 - syncbusy: rtc synchronization busy flag this bit is set when the cnt, ctrl or comp register is busy synchronizing between the rtc clock and system clock domains. 15.3.3 intctrl - real time counter interrupt control register ? bits 7:4 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bits 3:2 - compintlvl[1:0]: rtc compare match interrupt enable these bits enable the rtc compare match interrupt and select the interrupt level as described in ?interrupts and programmable multi-level interrupt controller? on page 95 . the enabled inter- rupt will trigger when the compif in the intflags register is set. ? bits 1:0 - ovfintlvl[1:0]: rtc overflow interrupt enable these bits enable the rtc overflow interrupt and select the interrupt level as described in ?interrupts and programmable multi-level interrupt controller? on page 95 . the enabled interrupt will trigger when the ovfif in the intflags register is set. bit 7654321 0 +0x01 ? ? ? ? ? ? ?syncbusystatus read/writerrrrrrrr/w initial value0000000 0 bit 76543210 +0x02 ? ? ? ? compintlvl[1:0] ovfintlvl[1:0] intctrl read/write r r r r r/w r/w r/w r/w initial value00000000
165 8210b?avr?04/10 xmega d 15.3.4 intflags - rtc interrupt flag register ? bits 7:2 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 1 - compif: rtc compare match interrupt flag this flag is set on the next count after a co mpare match condition occurs. the flag is cleared automatically when rtc compare match interrupt vector is executed. the flag can also be cleared by writing a one to its bit location. ? bit 0 - ovfif: rtc overflow interrupt flag this flag is set on the count after a overflow condition occurs. the flag is cleared automatically when rtc overflow interrupt vector is executed. the flag can also be cleared by writing a one to its bit location. 15.3.5 temp - rtc temporary register ? bits 7:0 - temp[7:0]: real time counter temporary register this register is used for 16-bit access to the counter value, compare value and top value regis- ters. the low byte of the 16-bit register is stored here when it is written by the cpu. the high byte of the 16-bit register is stored when low byte is read by the cpu. for more details refer to ?accessing 16-bits registers? on page 12 . 15.3.6 cnth - real time counter register h the cnth and cntl register pair represents th e 16-bit value cnt. cnt counts positive clock edges on the prescaled rtc clock. reading and writ ing 16-bit values require special attention, refer to ?accessing 16-bits registers? on page 12 for details. due to synchronization between rtc clock and the system clock domains, there is a latency of two rtc clock cycles from updating the register until this has an effect. application software needs to check that the syncbusy flag in the ?status - real time counter status register? on page 164 is cleared before writing to this register. bit 76543210 +0x03 ? ? ? ? ? ? compif ovfif intflags read/writerrrrrrr/wr/w initial value00000000 bit 76543210 +0x04 temp[7:0] temp read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x09 cnt[15:8] cnth read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000
166 8210b?avr?04/10 xmega d ? bits 7:0 - cnt[15:8]: real time counter value high byte these bits hold the 8 msb of the 16-bit real time counter value. 15.3.7 cntl - real time counter register l ? bits 7:0 - cnt[7:0]: real time counter value low byte these bits hold the 8 lsb of the 16-bit real time counter value. 15.3.8 perh - real time counter period register high the perh and perl register pair represents the 16-bit value per. per is constantly com- pared with the counter value ( cnt). a match will set the ovfif in the intflags register and clear cnt. reading and writing 16-bit val ues require special attention, refer to ?accessing 16- bits registers? on page 12 for details. due to synchronization between rtc clock and the system clock domains, there is a latency of two rtc clock cycles from updating the register until this has an effect. application software needs to check that the syncbusy flag in the ?status - real time counter status register? on page 164 is cleared before writing to this register. ? bits 7:0 - per[15:8]: real time counter period high byte these bits hold the 8 msb of the 16-bit rtc top value. 15.3.9 perl - real time counter period register l ? bits 7:0 - per[7:0]: real time counter period low byte these bits hold the 8 lsb of the 16-bit rtc top value. bit 76543210 +0x08 cnt[7:0] cntl read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x0b per[15:8] perh read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value11111111 bit 76543210 +0x0a per[7:0] perl read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 1 1 1 1 1 1 1 1
167 8210b?avr?04/10 xmega d 15.3.10 comph - real time counter compare register h the comph and compl register pair represent the 16-bit value comp. comp is constantly compared with the counter value (cnt). a co mpare match will set th e compif in the int- flags register. reading and writing 16-bit val ues require special attention, refer to ?configuration change protection? on page 12 for details. due to synchronization between rtc clock and the system clock domains, there is a latency of two rtc clock cycles from updating the register until this has an effect. application sw needs to check that the syncbusy flag in the ?status - real time counter status register? on page 164 is cleared before writing to this register. if the comp value is higher than the per value, no rtc compare match interrupt requests or events will ever be generated. ? bits 7:0 - comp[15:8]: real time counter compare register high byte these bits hold the 8 msb of the 16-bit rtc compare value. 15.3.11 compl - real time counter compare register l ? bits 7:0 - comp[7:0]: real time counter compare register low byte these bits hold the 8 lsb of the 16-bit rtc compare value. bit 76543210 +0x0d comp[15:8] comph read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x0c comp[7:0] compl read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000
168 8210b?avr?04/10 xmega d 15.4 register summary 15.5 interrupt vector summary address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 ctrl ? ? ? ? ? prescaler[2:0] 163 +0x01 status ? ? ? ? ? ? ? syncbusy 164 +0x02 intctrl ? ? ? ? compintlvl[1:0] ovfintlvl[1:0] 164 +0x03 intflags ? ? ? ? ? ? compif ovfif 165 +0x04 temp temp[7:0] 165 +0x08 cntl cnt[7:0] 165 +0x09 cnth cnt[15:8] 166 +0x0a perl per[7:0] 166 +0x0b perh per[15:8] 166 +0x0c compl comp[7:0] 167 +0x0d comph comp[15:8] 167 table 15-2. rtc interrupt vectors and their word offset address offset source interrupt description 0x00 ovf_vect real time counter overflow interrupt vector 0x02 comp_vect real time counter compare match interrupt vector
169 8210b?avr?04/10 xmega d 16. twi ? two wire interface 16.1 features ? fully independent master and slave operation ? multi-master, single master, or slave only operation ? phillips i 2 c compatible ? smbus compatible ? 100 khz and 400 khz support at low system clock frequencies ? slew-rate limited output drivers ? input filter provides noise suppression ? 7-bit, and general call address recognition in hardware ? address mask register for address masking or dual address match ? 10-bit addressing supported ? optional software address recognition prov ides unlimited number of slave addresses ? slave can operate in all sleep modes, including power down ? support for arbitration between start/ repeated start and data bit (smbus) ? slave arbitration allows support for address resolve protocol (arp) (smbus) 16.2 overview the two wire interface (twi) is bi-directi onal 2-wire bus communication, which is i 2 c and smbus compatible. a device connected to the bus must act as a mast er or slave.the master initiates a data transac- tion by addressing a slave on the bus, and telling whether it wants to transmit or receive data. one bus can have several masters, and an arbitration process handles priority if two or more masters try to transmit at the same time. the twi module in xmega implements both master and slave functionality. the master and slave functionality are separated from each other and can be enabled separately. they have separate control and status register, and separa te interrupt vectors. arbi tration lost, errors, colli- sion and clock hold on the bus will be detected in hardware and indicated in separate status flags available in both master and slave mode. the master module contains a baud rate generator for flexible clock generation. both 100 khz and 400 khz bus frequency at low system clock speed is supported. quick command and smart mode can be enabled to auto trigger operations and reduce software complexity. for the slave, 7-bit and general address call rec ognition is implemented in hardware. 10-bit addressing is also supported. a dedicated address mask register can act as a second address match register or as a mask register for the slave address to match on a range of addresses. the slave logic continues to operate in all slee p modes, including power down. this enables the slave to wake up from sleep on twi address matc h. it is possible to disable the address match- ing and let this be handled in software instead. this allows the slave to detect and respond to several addresses. smart mode can be enabled to auto trigger operations and reduce software complexity. the twi module includes bus state logic that collects information to detect start and stop conditions, bus collision and bus errors. this is used to de termine the bus st ate (idle, owner, busy or unknown) in master mode. the bus state logic continues to operate in all sleep modes including power down.
170 8210b?avr?04/10 xmega d it is possible to disable the internal twi driver s in the device, and enabling a 4-wire interface for connecting external bus drivers. 16.3 general twi bus concepts the two-wire interface (twi) provides a simple tw o-wire bi-directional bu s consisting of a serial clock line (scl) and a serial data line (sda). the two lines are open collector lines (wired-and), and pull-up resistors (rp) are the only external components needed to drive the bus. the pull-up resistors will provide a high level on the lines when none of the connect ed devices are driving the bus. a constant current source can be used as an alternative to the pull-up resistors. the twi bus is a simple and efficient method of interconnecting multiple devices on a serial bus. a device connected to the bus can be a master or slave, where the master controls the bus and all communication. figure 16-1 illustrates the twi bus topology. figure 16-1. twi bus topology a unique address is assigned to all slave devices connected to the bus, and the master will use this to address a slave and initiate a data transaction. 7-bit or 10-bit addressing can be used. several masters can be connected to the same bus, and this is called a multi-master environ- ment. an arbitration mechanism is provided for resolving bus ownership between masters since only one master device may own the bus at any given time. a device can contain both master and slave logic, and can emulate multiple slave devices by responding to more than one address. a master indicates the start of transaction by issuing a start condition (s) on the bus. an address packet with a slave address (address) and an indication whether the master wishes to read or write data (r/w ), is then sent. after all data packets (data) are transferred, the mas- ter issues a stop condition (p) on the bus to end the transaction. the receiver must acknowledge (a) or not-acknowledge (a ) each byte received. figure 16-2 shows a twi transaction. twi device #1 r p r p r s r s sda scl v cc twi device #2 r s r s twi device #n r s r s note: r s is optional
171 8210b?avr?04/10 xmega d figure 16-2. basic twi transaction diagram topology the master provides the clock signal for the tr ansaction, but a device connected to the bus is allowed to stretch the low level period of the clock to decrea se the clock speed. 16.3.1 electrical characteristics the twi in xmega follows the electr ical specificati ons and timing of i 2 c and smbus. these specifications are not 100% compliant so to ensure correct behavior th e inactive bus timeout period should be set in twi master mode. 16.3.2 start and stop conditions two unique bus conditions are used for marking the beginning (start) and end (stop) of a transaction. the master issues a start condition(s) by indicating a high to low transition on the sda line while the scl line is kept high. the master completes the transaction by issuing a stop condition (p), indicated by a low to high transition on the sda line while scl line is kept high. figure 16-3. start and stop conditions multiple start conditions can be issued during a single transaction. a start condition not directly following a stop condition, are named a repeated start condition (sr). p s address 6 ... 0 r/w ack ack 7 ... 0 data ack/nack 7 ... 0 data sda scl s a a/a r/w address data p a data address packet data packet #0 transaction data packet #1 direction the slave provides data on the bus the master provides data on the bus the master or slave can provide data on the bus sda scl start condition stop condition s p
172 8210b?avr?04/10 xmega d 16.3.3 bit transfer as illustrated by figure 16-4 a bit transferred on the sda line must be stable for the entire high period of the scl line. consequently the sda value can only be changed during the low period of the clock. this is ensured in hardware by the twi module. figure 16-4. data validity combining bit transfers results in the formation of address and data packets. these packets consist of 8 data bits (one byte) with the most sign ificant bit transferred first, plus a single bit not- acknowledge (nack) or acknowledge (ack) response. the addressed device signals ack by pulling the scl line low, and nack by leaving the line scl high during the ninth clock cycle. 16.3.4 address packet after the start condition, a 7-bit address followed by a read/write (r/w ) bit is sent. this is always transmitted by the master. a slave reco gnizing its address will ac k the address by pull- ing the data line low the next scl cycle, while all other slaves should keep the twi lines released, and wait for the next start and address. the 7-bit address, the r/w bit and the acknowledge bit combined is the address packet. only one address packet for each start condition is given, also when 10-bit addressing is used. the r/w specifies the direction of the transaction. if the r/w bit is low, it indicates a master write transaction, and the ma ster will transmit its data afte r the slave has acknowledged its address. opposite, for a master read operation the slave will st art to transmit data after acknowledging its address. 16.3.5 data packet data packets succeed an address packet or another data packet. all data packets are nine bits long, consisting of one data byte and an acknowl edge bit. the direction bit in the previous address packet determines the direction in which the data is transferred. 16.3.6 transaction a transaction is the complete transfer from a start to a stop condition, including any repeated start conditions in between. the twi standard defines three fundamental transac- tion modes: master write, master read, and combined transaction. figure 16-5 illustrates the master write transaction. the master init iates the transaction by issu- ing a start condition (s) followed by an addr ess packet with direction bit set to zero (address+w ). sda scl data valid change allowed
173 8210b?avr?04/10 xmega d figure 16-5. master write transaction given that the slave acknowledges the address, the master can start transmitting data (data) and the slave will ack or nack (a/a ) each byte. if no data packet s are to be transmitted, the master terminates the transaction by issuing a stop condition (p) directly after the address packet. there are no limitations to the number of data packets that can be transferred. if the slave signal a nack to the data, the master must assume that the slave cannot receive any more data and terminate the transaction. figure 16-6 illustrates the master read tr ansaction. the master initia tes the transacti on by issu- ing a start condition followed by an address packet with direct ion bit set to one (adress+r). the addressed slave must acknowledge the address for the master to be allowed to continue the transaction. figure 16-6. master read transaction given that the slave acknowledges the address, the master can start receiving data from the slave. there are no limitations to the number of data packets that can be transferred. the slave transmits the data while the master signals ack or nack after each data byte. the master ter- minates the transfer with a nack before issuing a stop condition. figure 16-7 illustrates a co mbined transaction. a combined transaction consists of several read and write transactions separated by a repeated start conditions (sr). figure 16-7. combined transaction s a a a/a p w address data data address packet data packet transaction n data packets s r a a a address data data p transaction address packet data packet n data packets s a sr a/a r/w data a/a p address data r/w address transaction address packet #1 n data packets m data packets address packet #2 direction direction a
174 8210b?avr?04/10 xmega d 16.3.7 clock and clock stretching all devices connected to the bus are allowed to stretch the low period of the clock to slow down the overall clock frequency or to insert wait states while processing data. a device that needs to stretch the clock can do this by holding/forcing th e scl line low after it de tects a low level on the line. three types of clock stretching can be defined as shown in figure 16-8 . figure 16-8. clock stretching if the device is in a sleep mode and a start co ndition is detected the clock is stretched during the wake-up period for the device. a slave device can slow down the bus frequency by stretching the clock periodically on a bit level. this allows the slave to run at a lower system clock frequency. however, the overall per- formance of the bus will be reduced accordin gly. both the master and slave device can randomly stretch the clock on a byte level basis before and after the ack/nack bit. this pro- vides time to process incoming or prepare outgoing data, or performing other time critical tasks. in the case where the slave is stre tching the clock the master will be forced into a wait-state until the slave is ready and vice versa. 16.3.8 arbitration a master can only start a bus transaction if it has detected that the bus is idle. as the twi bus is a multi master bus, it is possible that two devices initiate a transaction at the same time. this results in multiple masters owni ng the bus simultaneously. this is solved using an arbitration scheme where the master lo ses control of the bus if it is not able to trans mit a high level on the sda line. the masters who lose arbitration must then wait until the bus becomes idle (i.e. wait for a stop condition) before attempting to reacquire bus ownership. slave devices are not involved in the arbitration procedure. sda scl s ack/nack bit 0 bit 7 bit 6 periodic clock stretching random clock stretching wakeup clock stretching
175 8210b?avr?04/10 xmega d figure 16-9. twi arbitration figure 16-9 shows an example where two twi masters are contending for bus ownership. both devices are able to issue a start condition, but device1 loses arbitration when attempting to transmit a high level (bit 5) while device2 is transmitting a low level. arbitration between a repeated start condition and a data bit, a stop condition and a data bit, or a repeated start conditi on and stop condition are not allowed and will require special handling by software. 16.3.9 synchronization a clock synchronization algorithm is necessary fo r solving situations where more than one mas- ter is trying to control the scl line at the same time. the algorithm is based on the same principles used for clock stretching previously described. figure 16-10 shows an example where two masters are competing for the control over the bus clock. the scl line is the wired-and result of the two ma sters clock outputs. figure 16-10. clock synchronization a high to low transition on the scl line will force the line low for all masters on the bus and they start timing their low clock period. the timing length of the low clock period can vary between the masters. when a master (device1 in this case) has completed its low period it releases the scl line. however, the scl line will not go high before all masters have released it. conse- quently the scl line will be held low by the de vice with the longest low period (device2). devices with shorter low periods must insert a wa it-state until the clock is released. all masters start their high period when the scl line is released by all devices and has become high. the device1_sda sda (wired-and) device2_sda scl s bit 7 bit 6 bit 5 bit 4 device1 loses arbitration device1_scl scl (wired-and) wait state device2_scl high period count low period count
176 8210b?avr?04/10 xmega d device which first completes it s high period (device1) forces the clock line low and the proce- dure are then repeated. the result of this is that the device with the shortest clock period determines the high period while the low period of the clock is determined by the longest clock period. 16.4 twi bus state logic the bus state logic continuously monitors the activity on the twi bus lines when the master is enabled. it continues to operate in all sleep modes, including power down. the bus state logic includes start and stop cond ition detectors, collisi on detection, inactive bus timeout detection, and bit counter. this is used to determine the bus state. software can get the current bus state by reading the bus state bits in the master status register. the bus state can be 'unknown', 'idle', 'busy' or 'owner' and is determined according to the state diagram shown in figure 16-11 . the value of the bus state bits according to state is shown in binary in the figure. figure 16-11. bus state, state diagram after a system reset, the bus state is unknown. from this the bus state machine can be forced to enter idle by writing to the bus state bits accordingly. if no state is set by application software the bus state will become idle w hen a stop condition is detect ed. if the master inactive bus timeout is enabled the bus state will change to idle on the occurrence of a timeout. after a known bus state is established th e bus state will not re-enter the unknown state from any of the other states. only a system rese t or disabling the twi master will set the state to unknown. when the bus is idle it is ready for a new tr ansaction. if a start condition generated externally is detected, the bus becomes bu sy until a stop condition is detected. the st op condition will change the bus state to idle. if the master inactive bus timeout is enabled bus state will change from busy to idle on the occurrence of a timeout. p + timeout write address idle (0b01) s busy (0b11) unknown (0b00) owner (0b10) arbitration lost command p write address(sr) sr (s) reset p + timeout
177 8210b?avr?04/10 xmega d if a start condition is generated internally while in idle state the owner state is entered. if the complete transaction was performed without interference, i.e. no collisions are detected, the master will issue a stop conditi on and the bus stat e changes back to idle. if a collision is detected the arbitration is assumed lost and the bus state becomes busy until a stop condition is detected. a repeated start co ndition will only change the bus state if arbi tration is lost dur- ing the issuing of the repeated start. 16.5 twi master operation the twi master is byte-oriented with optional interrupt after each byte. there are separate inter- rupts for master write and master read. interrupt flags can also be used for polled operation. there are dedicated status flags for indicating ac k/nack received, bus error, arbitration lost, clock hold and bus state. when an interrupt flag is set, th e scl line is forced low. this will give the master time to respond or handle any data, and will in most cases requi re software interaction. figure 16-12 shows the twi master operation. the diamond shaped symbols (sw) indicate where software interaction is required. clearing the interrupt flags, releases the scl line. figure 16-12. twi master operation the number of interrupts generated is kept at a minimum by automatic handling of most condi- tions. quick command and smart mode can be enabled to auto trigger operations and reduce software complexity. idle s busy busy p sr p m3 m3 m2 m2 m1 m1 r data address w a/a data wait for idle application sw sw sr p m3 m2 busy m4 a sw a/a a/a a/a m4 a idle idle master read interrupt + hold master write interrupt + hold sw sw sw busy r/w sw driver software the master provides data on the bus slave provides data on the bus a a r/w busy m4 bus state mn diagram connections
178 8210b?avr?04/10 xmega d 16.5.1 transmitting address packets after issuing a start condition, the master starts performing a bus transaction when the mas- ter address register is written with the slave address and direction bit. if the bus is busy the twi master will wait until the bus becom es idle. when the bus is idle the master will issue a start condition on the bus before the address byte is transmitted. depending on arbitration and the r/w direction bit one of four distinct cases (1 to 4) arises fol- lowing the address packet. the different cases must be handled in software. 16.5.1.1 case m1: arbitration lost or bus error during address packet if arbitration is lost during the sending of the address packet the master write interrupt flag and arbitration lost flag are both set. serial data output to the sda line is disabled and the scl line is released. the master is no longer allowed to perform any operation on the bus until the bus state has changed back to idle. a bus error will behave in the same way as an arbitr ation lost condition, but the error flag is set in addition to write interrupt flag and arbitration lost flag. 16.5.1.2 case m2: address packet transmit complete - address not acknowledged by slave if no slave device responds to the address the master write interrupt flag is set and the master received acknowledge flag is set. the clock hold is active at this point preventing further activity on the bus. 16.5.1.3 case m3: address packet transmit complete - direction bit cleared if the master receives an ack from the slave, the master write interrupt flag is set, and the master received acknowledge flag is cleared. th e clock hold is active at this point preventing further activity on the bus. 16.5.1.4 case m4: address packet transmit complete - direction bit set if the master receives an ack from the slave, the master proceeds receiving the next byte of data from the slave. when the first data byte is received the master read interrupt flag is set and the master received acknowledge flag is cleare d. the clock hold is active at this point pre- venting further activity on the bus. 16.5.2 transmitting data packets assuming case 3 above, the master can start transmitting data by writing to the master data reg- ister. if the transfer was successful the slave will signal with ack. the master write interrupt flag is set, the master received acknowledge flag is cleared and the master can prepare new data to send. during data transf er the master is cont inuously monitoring the bus for collisions. the received acknowledge flag must be checked for each data packet transmitted before the next data packet can be transferred. the master is not allowed to continue transmitting data if the slave signals a nack. if a collision is detected and the master looses arbitration during transfe r, the arbitration lost flag is set. 16.5.3 receiving data packets assuming case 4 above the master has already received one byte from the slave. the master read interrupt flag is set, and the master must prepare to receive new data. the master must respond to each byte with ack or nack. indica ting a nack might not be successfully executed
179 8210b?avr?04/10 xmega d since arbitration can be lost during the transmiss ion. if a collision is detected the master looses arbitration and the arbitration lost flag is set. 16.6 twi slave operation the twi slave is byte-oriented with optional interr upts after each byte. there are separate slave data interrupt and address/stop interrupt. interrupt flags can also be used for polled operation. there are dedicated status flags for indicating ack/nack received, clock hold, collision, bus error and read/write direction. when an interrup t flag is set, the scl line is forced lo w. this will give the slave time to respond or handle any data, and will in most cases require software interaction. figure 16-13 . shows the twi slave operation. the diamond shapes symbols (sw) indicate where software interaction is required. figure 16-13. twi slave operation the number of interrupts generated is kept at a minimum by automatic handling of most condi- tions. quick command can be enabled to auto trigger operations and reduce software complexity. promiscuous mode can be enabled to allow the slave to respond to all received addresses. 16.6.1 receiving address packets when the twi slave is properly configured, it will wait for a start condition to be detected. when this happens, the successi ve address byte will be receiv ed and checked by the address match logic, and the slave will ack the correct address. if the received address is not a match, the slave will not acknowledge the address and wait for a new start condition. the slave address/stop interrupt flag is set when a start condition succeeded by a valid address packet is detected. a general call address will al so set the interrupt flag. a start condition immediately followed by a st op condition, is an illegal operation and the bus error flag is set. s s3 address s2 a s1 r w data a/a data p s2 sr s3 p s2 sr s3 slave address interrupt slave data interrupt a collision (smbus) sw sw sw sw a/a a/a sw release hold s1 a s1 sw interrupt on stop condition enabled s1 sw driver software the master provides data on the bus slave provides data on the bus sn diagram connections
180 8210b?avr?04/10 xmega d the r/w direction flag reflects the direction bit received with the address. this can be read by software to determine the type of operation currently in progress. depending on the r/w direction bit and bus condition one of four distinct cases (1 to 4) arises following the address packet. the different cases must be handled in software. 16.6.1.1 case 1: address packet accepted - direction bit set if the r/w direction flag is set, this indicates a master read operation. the scl line is forced low, stretching the bus clock. if ack is sent by the slave, the slave hardware will set the data interrupt flag indicating data is needed for transmit . if nack is sent by the slave, the slave will wait for a new condition and address match. 16.6.1.2 case 2: address packet accepted - direction bit cleared if the r/w direction flag is cleared this indicates a master write operation. the scl line is forced low, stretching the bus clock. if ack is sent by the slave, the slave will wait for data to be received. data, repeated start or stop can be received after this. if nack is indicated the slave will wait for a new start condition and address match. 16.6.1.3 case 3: collision if the slave is not able to send a high level or na ck, the collision flag is set and it will disable the data and acknowledge output from the slave logi c. the clock hold is released. a start or repeated star t condition will be accepted. 16.6.1.4 case 4: stop condition received. operation is the same as case 1 or 2 above with one exception. when the stop condition is received, the slave address/stop flag will be set indicating that a stop condition and not an address match occurred. 16.6.2 receiving data packets the slave will know when an address packet with r/w direction bit cleared has been success- fully received. after acknowledging this, the slave must be ready to receive data. when a data packet is received the data interrupt flag is set, and the slave must indicate ack or nack. after indicating a nack, the slave must expect a stop or repeated start condition. 16.6.3 transmitting data packets the slave will know when an address packet, with r/w direction bit set, has been successfully received. it can then start sending data by writing to the slave data register. when a data packet transmission is completed, the data interrupt flag is set. if the master indicates nack, the slave must stop transmitting data, and expect a stop or repeated start condition. 16.7 enabling external driver interface an external drivers interface can be enabled. wh en this is done the internal twi drivers with input filtering and slew rate control are bypas sed. the normal i/o pin function is used and the direction must be configured by the user softwa re. when this mode is enabled an external twi compliant tri-state driver is needed for connecting to a twi bus. by default port pin 0 (pn0) and 1 (pn1) is used for sda and scl. the external driver interface uses port pin 0 to 3 for the signal s sda_in, scl_in, sda_out and scl_out.
181 8210b?avr?04/10 xmega d 16.8 register d escription - twi 16.8.1 ctrl? twi common control register ? bit 7:2 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 1 - sdahold: sda hold time enable. setting this bit to one enables an internal hold time on sda with respect to the negative edge of scl. ? bit 0 - edien: external driver interface enable setting this bit enables the use of the external driver interface, clearing this bit enables normal two wire mode. see table 16-1 for details. 16.9 register descrip tion - twi master 16.9.1 ctrla - twi master control register a ? bit 7:6 - intlvl[1:0]: interrupt level the interrupt level (intlvl) bit select the interrupt level for the twi master interrupts. ? bit 5 - rien: read interrupt enable setting the read interrupt enable (rien) bit enables the read interrupt when the read interrupt flag (rif) in the status register is set. in addition the intlvl bits must be unequal zero for twi master interrupts to be generated. bit 76543210 +0x00 ? ? ? ? ? ? sdahold edien ctrl read/writerrrrrrr/wr/w initial value00000000 table 16-1. external driver interface enable edien mode comment 0normal twi two pin interface, slew rate control and input filter. 1 external driver interface four pin interface, standard i/o, no slew-rate control, no input filter. bit 76543210 +0x00 intlvl[1:0] rien wien enable ? ? ?ctrla read/write r/w r/w r/w r/w r/w r r r initial value00000000
182 8210b?avr?04/10 xmega d ? bit 4 - wien: write interrupt enable setting the write interrupt enable (wien) bit enables the write interrupt when the write interrupt flag (wif) in the status register is set. in addition the intlvl bits must be unequal zero for twi master interrupts to be generated. ? bit 3 - enable: enable twi master setting the enable twi master (enable) bit enables the twi master. ? bit 2:0 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. 16.9.2 ctrlb - twi master control register b ? bit 7:4 - reserved bits these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 3:2 - timeout[1:0]: inactive bus timeout setting the inactive bus ti meout (timeout) bits un equal zero will enable the inactive bus time- out supervisor. if the bus is inactive for longer than the timeout settings, the bus state logic will enter the idle state. figure 16-2 lists the timeout settings. ? bit 1 - qcen: quick command enable setting the quick command enable (qcen) bit enables quick command. when quick com- mand is enabled, a stop condition is sent immediate after the slave acknowledges the address. ? bit 0 - smen: smart mode enable setting the smart mode enable (smen) bit enables smart mode. when smart mode is enabled, the acknowledge action, as set by the ackact bit in control register c, is sent immediately after reading the data register. bit 76543210 +0x01 ? ? ? ? timeout[1:0] qcen smen ctrlb read/write r r r r r/w r/w r/w r/w initial value00000000 table 16-2. twi master inactive bus timeout settings timeout[1:0] group configuration description 00 disabled disabled, normally used for i 2 c 01 50us 50 s, normally used for smbus at 100 khz 10 100us 100 s 11 200us 200 s
183 8210b?avr?04/10 xmega d 16.9.3 ctrlc - twi master control register c ? bits 7:3 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 2 - ackact: acknowledge action the acknowledge action (ackact) bit defines the master's acknowledge behavior in master read mode. the acknowledge action is executed when a command is written to the cmd bits. if smen in control register b is set, the acknowledge action is performed when the data regis- ter is read. table 16-3 lists the acknowledge actions. ? bit 1:0 - cmd[1:0]: command writing the command (cmd) bits triggers a master operation as defined by table 16-4 . the cmd bits are strobe bits, and always read as zero. the acknowledge action is only valid in mas- ter read mode (r). in master write mode (w ), a command will only re sult in a repeated start or stop condition. the ackact bit and the cmd bits can be written at the same time, and then the acknowledge action will be updated before the command is triggered. writing a command to the cmd bits will clear t he master interrupt flag s and the clkhold flag. bit 76543210 +0x02 ? ? ? ? ? ackact cmd[1:0] ctrlc read/writerrrrrr/wr/wr/w initial value00000000 table 16-3. ackact bit description ackact action 0 send ack 1 send nack table 16-4. cmd bit description cmd[1:0] mode operation 00 x reserved 01 x execute acknowledge action succeeded by repeated start condition 10 w no operation r execute acknowledge action succeeded by a byte receive 11 x execute acknowledge action succeeded by issuing a stop condition
184 8210b?avr?04/10 xmega d 16.9.4 status - master status register ? bit 7 - rif: read interrupt flag this read interrupt flag (rif) is set when a byte is successfully received in master read mode, i.e. no arbitration lost or bus error occurred during the operation. writing a one to this bit location will clear the rif. when this flag is set the master forces the scl line low, stretching the twi clock period. clearing the interr upt flags will release the scl line. this flag is also automatically cleared when: ? writing to the addr register. ? writing to the data register. ? reading the data register. ? writing a valid command to the cmd bits in the ctrlc register. ? bit 6 - wif: write interrupt flag the write interrupt flag (wif) flag is set when a byte is transmitted in master write mode. the flag is set regardless of the occurrence of a bus error or an arbitration lost condition. the wif is also set if arbitration is lost during sending of nack in master read mode, and if issuing a start condition when the bus state is unknown. writing a one to this bit location will clear the wif. when this flag is set the master forces the scl line low, stretching the twi clock period. clearing the interrupt flag s will release the scl line. the flag is also automatically cleared for the same conditions as rif. ? bit 5 - clkhold: clock hold the master clock hold (clkhold) flag is set wh en the master is holdi ng the scl line low. this is a status flag, and a read only bit that is set when the rif and wif is set. clearing the interrupt flags and releasin g the scl line, will indirectly clear this flag. the flag is also automatically cleared for the same conditions as rif. ? bit 4 - rxack: received acknowledge the received acknowledge (rxack) flag contains the most recently received acknowledge bit from slave. this is a read only flag. when read as zero the most recent acknowledge bit from the slave was ack, and when read as one the most recent acknowledge bit was nack. ? bit 3 - arblost: arbitration lost the arbitration lost (arblost) flag is set if arbi tration is lost while transmitting a high data bit, a nack bit, or while issuing a start or repeated start condition on the bus. writing a one to this bit location w ill clear the arblost flag. writing the addr register will auto matically clear the arblost flag. bit 76543210 +0x03 rif wif clkhold rxack arblost buserr busstate[1:0] status read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000
185 8210b?avr?04/10 xmega d ? bit 2 - buserr: bus error the bus error (buserr) flag is set if an illegal bus condition has occurred. an illegal bus condi- tion occurs if a repeated start or stop condition is detected, and the number of bits from the previous start condition is not a multiple of nine. writing a one to this bit location will clear the buserr flag. writing the addr register will auto matically clear the buserr flag. ? bit 1:0 - busstate[1:0]: bus state the bus state (busstate) bits indicate the current twi bus state as defined in table 16-5 . the change of bus state is dependent on bus activity. refer to the section 16.4 ?t wi bus state logic? on page 176 . writing 01 to the busstate bits forces the bus state logic into idle state. the bus state logic cannot be forced into any other state. when the master is disabled, and after reset the bus state logic is disabled and the bus state is unknown. 16.9.5 baud - twi baud rate register the baud rate (baud) register defines the relation between the system clock and the twi bus clock (scl) frequency. the frequency relation can be expressed by using the following equation: [1] the baud register must be set to a value that results in a twi bus clock frequency (f twi ) equal or less 100 khz or 400 khz dependent on standard used by the application. the following equa- tion [2] expresses equation [1] with respect to the baud value: [2] the baud register should be written while the master is disabled. table 16-5. twi master bus state busstate[1:0] group configuration description 00 unknown unknown bus state 01 idle idle 10 owner owner 11 busy busy bit 76543210 +0x04 baud[7:0] baud read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 f twi f sys 2(5 twmbr ) + --------------------------------------- - [hz] = twmbr f sys 2 f twi ------------- - 5 ? =
186 8210b?avr?04/10 xmega d 16.9.6 addr - twi master address register when the address (addr) register is written with a slave address and the r/w -bit while the bus is idle, a start condition is issued, and the 7-bit slave address and the r/w -bit are transmitted on the bus. if the bus is already owned when addr is written, a repeated start is issued. if the previous transaction was a master read and no acknowledge is sent yet, the acknowledge action is sent before the repeated start condition. after completing the operation and the acknowledge bit from the slave is received, the scl line is forced low if arbitration was not lost. the wif is set. if the bus state is unknown when addr is written. the wif is set, and the buserr flag is set. all twi master flags are automatically cleared when addr is written. this includes buserr, arblost, rif, and wif. the master addr can be read at any time without interfering with ongoing bus activity. 16.9.7 data -twi master data register the data (data) register is used when transmitting and receiving data. during data transfer, data is shifted from/to the data register and to/from the bus. this implies that the data register cannot be accessed during byte transfers, and this is protected in hardware. the data register can only be accessed when the scl line is held low by the master, i.e. when clkhold is set. in master write mode, writing th e data register will trigger a data byte transfer, followed by the master receiving the acknowledge bit from the slave. the wif and the clkhold flag are set. in master read mode the rif and the clkhold flag are set when one byte is received in the data register. if smart mode is enabled, reading th e data register will trigger the bus opera- tion as set by the ackact bit. if a bus error occurs during reception the wif and buserr flag are set instead of the rif. accessing the data register will clear the master interrupt flags an d the clkhold flag. bit 76543210 +0x05 addr[7:0] addr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x05 data[7:0] data read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000
187 8210b?avr?04/10 xmega d 16.10 register descr iption - twi slave 16.10.1 ctrla - twi slav e control register a ? bit 7:6 - intlvl[1:0]: twi slave interrupt level the slave interrupt level (intlvl) bits select the interrupt level for the twi slave interrupts. ? bit 5 - dien: data interrupt enable setting the data interrupt enable (dien) bit enables the data interrupt when the data interrupt flag (dif) in the status register is set. the intlvl bits must be unequal zero for the interrupt to be generated. ? bit 4 - apien: address/stop interrupt enable setting the address/stop interrupt enable (apien) bit enables the address/stop interrupt when the address/stop interrupt flag (apif) in the stat us register is set. the intlvl bits must be unequal zero for interrupt to be generated. ? bit 3 - enable: enable twi slave setting the enable twi slave (enable) bit enables the twi slave. ? bit 2 - pien: stop interrupt enable setting the stop interrupt enable (pien) bit will set the apif in the status register when a stop condition is detected. ? bit 1 - pmen: promiscuous mode enable by setting the promiscuous mode enable (pmen) bit, the slave address match logic responds to all received addresses. if this bit is cleared, the address match logic uses the addr register to determine which address to recognize as its own address. ? bit 0 - smen: smart mode enable setting the smart mode enable (smen) bit enables smart mode. when smart mode is enabled, the acknowledge action, as set by the ackact bit in the ctrlb register, is sent immediately after reading the data register. 16.10.2 ctrlb - twi slav e control register b ? bit 7:3 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. bit 765432 1 0 +0x00 intlvl[1:0] dien apien enable pien pmen smen ctrla read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value000000 0 0 bit 76543210 +0x01 ? ? ? ? ? ackact cmd[1:0] ctrlb read/write r r r r r r/w r/w r/w initial value00000000
188 8210b?avr?04/10 xmega d ? bit 2 - ackact: acknowledge action the acknowledge action (ackact) bit defines the slave's acknowledge behavior after an address or data byte is received from the ma ster. the acknowledge action is executed when a command is written to the cmd bits. if the smen bit in the ctrla register is set, the acknowl- edge action is performed when the data register is read. table 16-6 lists the acknowledge actions. ? bit 1:0 - cmd[1:0]: command writing the command (cmd) bits triggers the slave operation as defined by table 16-7 . the cmd bits are strobe bits, and always read as zero. the operation is dependent on the slave interrupt flags, dif and apif. the acknowledge ac tion is only executed when the slave receives data bytes or address byte from the master. writing the cmd bits will automatically clear th e slave interrupt flags , the clkhold flag and release the scl line. the ackact bit and cmd bits can be written at the same time, and then the acknowledge action will be updated before the command is triggered. 16.10.3 status? twi slave status register table 16-6. twi slave acknowledge action ackact action 0 send ack 1 send nack table 16-7. twi slave command cmd[1:0] dir operation 00 x no action 01 x reserved 10 used to complete transaction 0 execute acknowledge action succeeded by waiting for any start (s/sr) condition. 1 wait for any start (s/sr) condition. 11 used in response to an address byte (apif is set) 0 execute acknowledge action succeeded by reception of next byte. 1 execute acknowledge action succeeded by the dif being set used in response to a data byte (dif is set ) 0 execute acknowledge action succeeded by waiting for the next byte. 1 no operation. bit 76543210 +0x02 dif apif clkhold rxack coll buserr dir ap status read/write r/w r/w r/w r r/w r/w r/w r/w initial value00000000
189 8210b?avr?04/10 xmega d ? bit 7 - dif: data interrupt flag the data interrupt flag (dif) is set when a data by te is successfully received, i.e. no bus error or collision occurred during the operation. writi ng a one to this bit location will clear the dif. when this flag is set the slave forces the scl line low, stretching the twi clock period. clearing the interrupt flags w ill release the scl line. this flag is also automatically cleared when writing a valid command to the cmd bits in the ctrlb register ? bit 6 - apif: address/stop interrupt flag the address/stop interrupt flag (apif) is set when the slave detects that a valid address has been received, or when a transmit collision is detect ed. if the pien bit in the ctrla register is set a stop condition on the bus will also set apif. writing a one to this bi t location will clear the apif. when this flag is set the slave forces t he scl line low, stretching the twi clock period. clearing the interrupt flag s will release the scl line. the flag is also automatically cleared for the same condition as dif. ? bit 5 - clkhold: clock hold the slave clock hold (clkhold) flag is set when the slave is holding the scl line low.this is a status flag, and a read only bit that is set when the dif or apif is set. clearing the interrupt flags and releasing the scl line, will indirectly clear this flag. ? bit 4 - rxack: received acknowledge the received acknowledge (rxack) flag contains the most recently received acknowledge bit from the master. this is a read only flag. wh en read as zero the most recent acknowledge bit from the maser was ack, and when read as one the most recent acknowledge bit was nack. ? bit 3 - coll: collision the slave collision (coll) flag is set when slave is not been able to transfe r a high data bit or a nack bit. if a collision is detected, the slav e will commence its normal operation, disable data and acknowledge output, and no low values will be shifted out onto the sda line. writing a one to this bit location will clear the coll flag. the flag is also automatically cleared when a start or repeated start condition is detected. ? bit 2 - buserr: twi slave bus error the slave buss error (buserr) flag is set w hen an illegal bus condition has occurs during a transfer. an illegal bus condition occurs if a repeated start or stop condition is detected, and the number of bits from the previous start condition is not a multiple of nine. writing a one to this bit location will clear the buserr flag. for bus errors to be detected, the bus state logic must be enabled. this is done by enable twi master. ? bit 1 - dir: read/write direction the read/write direction (dir) flag reflects t he direction bit from the last address packet received from a master. when this bit is read as one, a master read operation is in progress. when read as zero a master write operation is in progress.
190 8210b?avr?04/10 xmega d ? bit 0 - ap: slave address or stop the slave address or stop (ap) flag indicates whether a valid address or a stop condition caused the last setting of the apif in the status register. 16.10.4 addr - twi slave address register the slave address (addr) regist er contains the twi slave address used by the slave address match logic to determine if a master has addressed the slave. when using 7-bit or 10-bit address recognition mode, the up per 7-bits of the address regist er (addr[7:1]) represents the slave address. the least significant bit (addr[0]) is used for general call address recognition. setting addr[0] enables general call address recognition logic. when using 10-bit addressing the address match logic only support hardware address recogni- tion of the first byte of a 10-bit address. by setting addr[7:1] = "0b11110nn", 'nn' represents bit 9 and 8 or the slave address. the next byte receiv ed is bit 7 to 0 in the 10-bit address, and this must be handled by software. when the address match logic detects that a valid address byte is received, the apif is set, and the dir flag is updated. if the pmen bit in the ctrla register is set, the address match logic responds to all addresses transmitted on the twi bus. the addr register is not used in this mode. 16.10.5 data - twi slave data register the data (data) register is used when transm itting and received data. during data transfer, data is shifted from/to the data register and to/from the bus. this implies that the data register cannot be accessed during byte transfers, and this is protected in hardware. the data register can only be accessed when the scl line is held low by the slave, i.e. when clkhold is set. when a master is reading data from the slave, data to send must be written to the data regis- ter. the byte transfer is started when the mast er start to clock the data byte from the slave, followed by the slave receiving the acknowledge bit from the master. the dif and the clkhold flag are set. when a master write data to the slave the dif and the clkhold flag are set when one byte is received in the data register. if smart mode is enabled, reading the data register will trigger the bus operation as set by the ackact bit. accessing the data register will clear the slave interrupt flags and the clkhold flag. table 16-8. twi slave address or stop ap description 0 a stop condition generated the interrupt on apif 1 address detection generated the interrupt on apif bit 76543210 +0x03 addr[7:0] addr read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x04 data[7:0] data read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
191 8210b?avr?04/10 xmega d 16.10.6 addrmask - twi slave address mask register ? bit 7:1 - addrmask[7:1]: read/write direction these bits in the addrmask register can act as a second address match register, or an address mask regi ster dependi ng on the addren setting. if addren is set to zero, addrmask can be loa ded with a 7-bit slave ad dress mask. each bit in addrmask can mask (disable) the corresponding address bit in the addr register. if the mask bit is one the address match between the incoming address bit and the corresponding bit in addr is ignored, i.e. ma sked bits will always match. if addren is set to one, addrmask can be l oaded with a second slave address in addition to the addr register. in th is mode, the slave will match on 2 unique addresses, one in addr and the other in addrmask. ? bit 0- addren: address enable by default this bit is zero and the addrmask bits acts as an add ress mask to the addr regis- ter. if this bit is set to one, the slave addres s match logic responds to the 2 unique addresses in addr and addrmask. bit 76543210 +0x05 addrmask[7:1] addren addrmask read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000
192 8210b?avr?04/10 xmega d 16.11 register summary - twi 16.12 register summary - twi master 16.13 register summary - twi slave 16.14 interrupt vector summary address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 ctrl ? ? ? ? ? ? sdahold edien 181 +0x01 master offset address for twi master +0x08 slave offset address for twi slave address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 ctrla intlvl[1:0] rien wien enable ? ? ?181 +0x01 ctrlb ? ? ? ? timeout[1:0] qcen smen 182 +0x02 ctrlc ? ? ? ? ? ackact cmd[1:0] 183 +0x03 status rif wif clkhold rxack arblost buserr busstate[1:0] 184 +0x04 baud baud[7:0] 185 +0x05 addr addr[7:0] 186 +0x06 data data[7:0] 186 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 ctrla intlvl[1:0] dien apien enable pien tpmen smen 187 +0x01 ctrlb ? ? ? ? ? ackact cmd[1:0] 187 +0x02 status dif apif clkhold rxack coll buserr dir ap 188 +0x03 addr addr[7:0] 190 +0x04 data data[7:0] 190 +0x05 addrmask addrm ask[7:1] addren 191 table 16-9. twi interrupt vectors and their word offset addresses offset source interr upt description 0x00 master_vect twi ma ster interrupt vector 0x02 slave_vect twi slave interrupt vector
193 8210b?avr?04/10 xmega d 17. spi ? serial peripheral interface 17.1 features ? full-duplex, three-wire synchronous data transfer ? master or slave operation ? lsb first or msb first data transfer ? eight programmable bit rates ? end of transmission interrupt flag ? write collision flag protection ? wake-up from idle mode ? double speed (ck/2) master spi mode 17.2 overview the serial peripheral interfac e (spi) is a high-speed synchronous data transfer interface using three or four pins. it allows fast communication between an xmega device and peripheral devices or between several avr devices. th e spi supports full duplex communication. a device connected to the bus must act as a master or slave.the master initiates and controls all data transactions. the interconnection between master and slave cpus with spi is shown in figure 17-1 on page 193 . the system consists of two shift registers, and a master clock gener- ator. the spi master initiates the communicati on cycle when pulling low the slave select (ss ) pin of the desired slave. master and slave prepare the data to be sent in their respective shift registers, and the master generates the required clock pulses on the sck line to interchange data. data is always shifted from master to slave on the master out - slave in (mosi) line, and from slave to master on the master in - slave out (miso) line. after each data packet, the mas- ter can synchronize the slave by pulling high the ss line. figure 17-1. spi master-slave interconnection the xmega spi module is single buffered in the transmit direction and double buffered in the receive direction. this means that bytes to be transmitted cannot be written to the spi data reg- ister before the entire shift cycle is completed. when receiving data, a received character must be read from the data register before the next character has been completely shifted in. other- wise, the first byte is lost. shift enable
194 8210b?avr?04/10 xmega d in spi slave mode, the control logic will sample the incoming signal of the sck pin. to ensure correct sampling of this clock signal, the minimum low and high periods must be: low period: longer than 2 cpu clock cycles. high period: longer than 2 cpu clock cycles. when the spi module is enabled, the data direction of the mosi, miso, sck, and ss pins is overridden according to table 17-1 . the pins with user defined direction, must be configured from software to have the correct direction according to the application. 17.3 master mode when configured as a master, the spi interface has no automatic control of the ss line. the ss pin must be configured as output, and controlled by user software. if the bus consists of several spi slaves and/or masters, a spi master can use general i/o pins to control the ss line to each of the slaves on the bus. writing a byte to the data register starts the spi clock generator, and the hardware shifts the eight bits into the selected slave. after shifting one byte, the spi clock generator stops and the spi interrupt flag is set. the master may continue to shift the next byte by writing new data to the data register, or signal the end of transfer by pulling the ss line high. the last incoming byte will be kept in the buffer register. if the ss pin is configured as an input, it must be held high to ensure master operation. if the ss pin is input and being driven low by external circuitry, the spi module will interpret this as another master trying to take control of the bus. to avoid bu s contention, the ma ster will take the following action: 1. the master enters slave mode. 2. the spi interrupt flag is set. 17.4 slave mode when configured as a slave, the spi interface will remain sleeping with miso tri-stated as long as the ss pin is driven high. in this state, software may update the contents of the data register, but the data will not be shifte d out by incoming clock pulses on the sck pin until the ss pin is driven low. if ss is driven low and assuming the miso pin is configur ed as output, the slave will start to shift out data on the first sck clock pulse. as one byte has been completely shifted, the spi interrupt flag is set. the slave may continue to place new data to be sent into the data reg- ister before reading the incoming data. the last incoming byte will be kept in the buffer register. when ss is driven high, the spi logic is reset, an d the spi slave will not receive any data. any partially received packet in the shift register will be dropped. table 17-1. spi pin overrides pin direction, master spi direction, slave spi mosi user defined input miso input user defined sck user defined input ss user defined input
195 8210b?avr?04/10 xmega d as the ss pin is used to signal start and end of trans fer, it is also usef ul for doing packet/byte synchronization, keeping the slave bit counter synchronous with the master clock generator. 17.5 data modes there are four combinations of sck phase and polarity with respect to serial data. the spi data transfer formats are shown in figure 17-2 . data bits are shifted out and latched in on opposite edges of the sck signal, ensuring suffici ent time for data signals to stabilize. leading edge is the first clock edge in a clock cycl e. trailing edge is the last clock edge in a clock cycle. figure 17-2. spi transfer modes table 17-2. spi modes mode leading edge trailing edge 0 rising, sample falling, setup 1 rising, setup falling, sample 2 falling,sample rising, setup 3 falling, setup rising, sample bit 1 bit 6 l s b m s b mode 0 s ample i mo s i/mi s o change 0 mo s i pin change 0 mi s o pin mode 2 ss m s b l s b bit 6 bit 1 bit 5 bit 2 bit 4 bit 3 bit 3 bit 4 bit 2 bit 5 m s b first (dord = 0) l s b first (dord = 1) mode 1 s ample i mo s i/mi s o change 0 mo s i pin change 0 mi s o pin mode 3 ss m s b l s b bit 6 bit 1 bit 5 bit 2 bit 4 bit 3 bit 3 bit 4 bit 2 bit 5 bit 1 bit 6 l s b m s b m s b first (dord = 0) l s b first (dord = 1)
196 8210b?avr?04/10 xmega d 17.6 register description 17.6.1 ctrl - spi control register ? bit 7 - clk2x: spi clock double when this bit is set the spi speed (sck freq uency) will be doubled in master mode (see table 17-4 on page 197 ). ? bit 6 - enable: spi enable setting this bit enables the spi modules. this bit must be set to enable any spi operations. ? bit 5 - dord: data order dord decide the data order when a byte is shifted out from the data register. when dord is written to one, the lsb of the data byte is transmitted first, and when dord is written to zero, the msb of the data byte is transmitted first. ? bit 4 - master: master/slave select this bit selects master mode when written to one, and slave mode when written to zero. if ss is configured as an input and is driven low while master is set, master will be cleared. ? bit 3:2 - mode[1:0]: spi mode these bits select the transfer mode. the four combinations of sck phase and polarity with respect to serial data is shown in figure 17-3 on page 196 . this decide whether the first edge in a clock cycles (leading edge) is ri sing or falling, and if data setup and sample is on lading or trail- ing edge. when the leading edge is rising the bit sck is low when idle, and when the leading edge is fall- ing the sck is high when idle. table 17-3. spi transfer modes ? bits 1:0 - prescaler[1:0 ]: spi clock prescaler these two bits control the sck rate of the device configured in a master mode. these bits have no effect in slave mode. bit 76543210 +0x00 clk2x enable dord master mode[1:0] prescaler[1:0] ctrl read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 mode[1:0] group configuration leading edge trailing edge 00 0 rising, sample falling, setup 01 1 rising, setup falling, sample 10 2 falling,sample rising, setup 11 3 falling, setup rising, sample
197 8210b?avr?04/10 xmega d the relationship between sck and the peripheral clock frequency (clk per )is shown in table 17- 4 on page 197 . 17.6.2 intctrl - spi interrupt control register ? bits 7:2 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bits 1:0 - intlvl[1:0]: spi interrupt level these bits enable the spi interrupt and select the interrupt level as described in ?interrupts and programmable multi-level interrupt controller? on page 95 . the enabled interrupt will be trig- gered when the if in the status register is set. 17.6.3 status - spi status register ? bit 7 - if: spi interrupt flag when a serial transfer is complete and one byte is completely shifted in/out of the data regis- ter, the if bit is set. if ss is an input and is driven low when the spi is in ma ster mode, this will also set the if bit. the if is cleared by hardware when executing the corresponding interrupt handling vector. alternatively, the spif bit can be cleared by first reading the status register with if set, and then access the data register. table 17-4. relationship between sck and the peripheral clock (clk per ) frequency clk2x prescaler[1:0] sck frequency 000clk per /4 001clk per /16 010clk per /64 011clk per /128 100clk per /2 101clk per /8 110clk per /32 111clk per /64 bit 76543210 +0x01 ? ? ? ? ? ? intlvl[1:0] intctrl read/writerrrrrrr/wr/w initial value00000000 bit 76543210 +0x02 if wcol ? ? ? ? ? ?status read/writerrrrrrrr initial value 0 0 0 0 0 0 0 0
198 8210b?avr?04/10 xmega d ? bit 6 - wrcol: write collision flag the wrcol bit is set if the data register is written during a data transfer. the wrcol bit is cleared by first reading the status register with wrcol set, and then accessing the data register. ? bit 5:0 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. 17.6.4 data - spi data register the data register used for sending and receiving data. writing to the register initiates the data transmission, and the byte written to the register will be shifted out on th e spi output line. read- ing the register causes the shift register receive buffer to be read, and return the last bytes successfully received. 17.7 register summary 17.8 spi interrupt vectors bit 76543210 +0x03 data[7:0] data read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 ctrl clk2x enable dord master mode[1:0] prescaler[1:0] 196 +0x01 intctrl ? ? ? ? ? ? intlvl[1:0] 197 +0x02 status if wrcol ? ? ? ? ? ?197 +0x03 data data[7:0] 198 table 17-5. spi interrupt vector and its offset word address offset source interrupt description 0x00 spi_vect spi interrupt vector
199 8210b?avr?04/10 xmega d 18. usart 18.1 features ? full duplex operation (independent se rial receive and transmit registers) ? asynchronous or synchronous operation ? master or slave clocked synchronous operation ? enhanced baud rate generator ? supports serial frames with 5, 6, 7, 8, or 9 data bits and 1 or 2 stop bits ? odd or even parity generation and parity check supported by hardware ? data overrun and framing error detection ? noise filtering includes false start bit detection and digital low pass filter ? separate interrupts on tx complete, tx data register empty and rx complete ? multi-processor communication mode ? double speed asynchronous communication mode ? master spi mode, three-wire synchronous data transfer ? supports all four spi modes of operation (mode 0, 1, 2, and 3) ? lsb first or msb first data tr ansfer (configurable data order) ? queued operation (double buffered) ? high speed operation (f xck,max = f per /2) ? ircom module for irda compliant pulse modulation/demodulation 18.2 overview the universal synchronous and asynchronous serial receiver and transmitter (usart) is a highly flexible serial communica tion module. the usart supports full duplex communication, and both asynchronous and clocked synchronous operation. the usart can be set in master spi compliant mode and be used for spi communication. communication is frame based, and the frame format can be customized to support a wide range of standards. the usart is buffered in both direction, enabling continued data transmis- sion without any delay between frames. there are separate interrupt vectors for receive and transmit complete, enabling fully interrupt driven communication. frame error and buffer over- flow are detected in hardware and indicated with separate status flags. even or odd parity generation and parity check can also be enabled. a block diagram of the usart is shown in figure 18-1 on page 200 . the main parts are the clock generator, the transmitter and the receiver, indicated in dashed boxes.
200 8210b?avr?04/10 xmega d figure 18-1. usart block diagram the clock generation logic has a fractional baud rate generator that is able to generate a wide range of usart baud rates. it also includes sync hronization logic for exte rnal clock input in syn- chronous slave operation. the transmitter consists of a single write buffe r (data), a shift register, parity generator and control logic for handling different frame formats. the write buffer allows continuous data trans- mission without any delay between frames. the receiver consists of a two level fifo receive buffer (data), and a shift register. data and clock recovery units ensure robust synchronization and noise filtering during asynchronous data reception. it includes frame error, buffer overflow and parity error detection. when the usart is set in master spi compliant mode, all usart specif ic logic is disabled, leaving the transmit and receive buffers, shift registers, and baud rate generator enabled. pin control and interrupt generation is identical in both modes. the registers are used in both modes, but the functionality differs for some control settings. an ircom module can be enabled for one usart to support irda 1.4 physical compliant pulse modulation and demodulation for baud rates up to 115.2 kbps. for details refer to ?ircom - ir communication module? on page 220 for details. parity generator bsel [h:l] data (transmit) ctrla ctrlb ctrlc baud rate generator fractional devide transmit shift register receive shift register rxd txd pin control data (receive) pin control xck data recovery clock recovery pin control tx control rx control parity checker data bus osc sync logic clock generator transmitter receiver
201 8210b?avr?04/10 xmega d 18.3 clock generation the clock used for baud rate generation, and for shifting and sampling data bits is generated internally by the fractional baud rate generator or externally from the transfer clock (xck) pin. five modes of clock generation are supported: normal and double speed asynchronous mode, master and slave synchronous mode, and master spi mode. figure 18-2. clock generation logic, block diagram.i 18.3.1 internal clock generation - the fractional baud rate generator the fractional baud rate generator is used for internal clock generation for asynchronous modes, synchronous master mode, and spi master mode operation. the generated output fre- quency (f baud ) is given by the period setting (bsel), an optional scale setting (bsacle) and the peripheral clock frequency (f per ). table 18-1 on page 202 contains equations for calculating the baud rate (in bits per second) and for calculati ng the bsel value for each mode of operation. bsel can be set to any value be tween 0 and 4095. it also show the maxi mum baud rate versus peripheral clock speed. fractional baud rate generation can be used in asynchronous mode of operation to increase the average resolution. a scale factor (bscale) allows the baud rate to be optionally left or right scaled. choosing a positive scale value will result s in right scaling, which increase the period and consequently reduce the frequency of the produced baud rate, without changing the resolu- tion. if the scale value is negative the divider uses fractional arithmetic counting to increase the resolution by distributing the fractional divide va lue over time. bscale can be set to any value from -7 to +7, where 0 implies no scaling. there is a limit to how high the scale factor can be and the value 2 bscale must be at least half of the minimum number of clock cycles a frame takes, see section 18.9 on page 210 for more details. baud rate generator /2 bsel /4 /2 sync register f osc xck pin txclk clk2x umsel [1] ddr_xck 0 1 0 1 xcki xcko ddr_xck rxclk 0 1 1 0 edge detector port_inv f baud
202 8210b?avr?04/10 xmega d note: 1. the baud rate is defined to be the transfer rate in bit per second (bps) 18.3.2 external clock external clock is used in synchronous slave mode operation. the xck clock input is sampled on the peripheral clock frequency (f per ) by a synchronization register to minimize the chance of meta-stability. the output from the synchronization register is then pass ed through an edge detector. this process introduces a delay of two peripheral clock periods, and therefore the max- imum external xck clock frequency (f xck )is limited by the following equation: each high and low period the xck clock cycles must be sampled twice by the peripheral clock. if the xck clock has jitter, or the high/low pe riod duty cycle is not 50/50, the maximum xck clock speed must be reduced accordingly. 18.3.3 double speed operation (clk2x) double speed operation can be enabled to allow for higher baud rates on lower peripheral clock frequencies under asynchronous operation. when double speed operation is enabled the baud rate for a given asynchronous baud rate setting as shown in table 18-1 on page 202 will be dou- bled. in this mode the receiver will use half the number of samples (reduced from 16 to 8) for data sampling and clock recovery. due to the reduced sampling more accurate baud rate setting and peripheral clock are required. see ?asynchronous data reception? on page 207 for more details on accuracy. table 18-1. equations for calculating baud rate register setting operating mode conditions equation for calculation baud rate (1) equation for calculation bsel value asynchronous normal speed mode (clk2x = 0) bscale 0 bscale < 0 asynchronous double speed mode (clk2x = 1) bscale 0 bscale < 0 synchronous and spi master mode f baud f per 16 ---------- - f baud f per 2 bscale 16( ? bsel 1) + ------------------------------------------------------------- - = bsel f per 2 bscale 16 ? f baud ------------------------------------------------ 1 ? = f baud f per 16 ---------- - f baud f per 16((2 bscale bsel ) ? 1) + ------------------------------------------------------------------ - = bsel 1 2 bscale --------------------- f per 16 f baud --------------------- - 1 ? ?? ?? = f baud f per 8 ---------- - f baud f per 2 bscale 8 bsel 1 + () ?? --------------------------------------------------------------- = bsel f per 2 bscale 8 ? f baud --------------------------------------------- 1 ? = f baud f per 8 ---------- - f baud f per 8((2 bscale bsel ) ? 1) + --------------------------------------------------------------- - = bsel 1 2 bscale --------------------- f per 8 f baud ------------------ - 1 ? ?? ?? = f baud f per 2 ---------- - < f baud f per 2 bsel 1 + () ? ------------------------------------ - = bsel f per 2 f baud ------------------ - 1 ? = f xck f per 4 ---------- - <
203 8210b?avr?04/10 xmega d 18.3.4 synchronous clock operation when synchronous mode is used, the xck pin cont rols whether the transmission clock is input (slave mode) or output (master mode). the corresponding port pin must be set to output for master mode and to input for slave mode . the normal port operation of the xck pin will be over- ridden. the dependency between the clock edges and data sampling or data change is the same. data input (on rxd) is sampled at the opposite xck clock edge of the edge where data output (txd) is changed. figure 18-3. synchronous mode xckn timing. using the inverted i/o (inven) setting in the pi n configuration register for the corresponding xck port pin, it is selectable which xck clock edge is used for data sampling and which is used for data change. if inverted i/o is disabled (inven=0) data will be changed at rising xck clock edge and sampled at falling xck clock edge. if inverted i/o is enable d (inven=1) data will be changed at falling xck clock edge and sampled at rising xck cloc k edge. for more details, see in ?i/o ports? on page 106. 18.3.5 spi clock generation for spi operation only master mode with internal clock generation is supported. this is identical to the usart synchr onous master mode and th e baud rate or bsel se tting are calculated by using the same equations, see table 18-1 on page 202 . there are four combinations of the xck (sck) clock phase and polarity with respect to serial data, and these are determined by the clock phase (ucpha) control bit and the inverted i/o pin (inven) setting. the data transfer timing diagrams are shown in figure 18-4 on page 204 . data bits are shifted out and latched in on opposite edges of the xck signal, ensuring sufficient time for data signals to stabilize. the ucph a and inven settings are summarized in table 18-2 on page 203 . changing the setting of any of these bits during transmission will corrupt for both the receiver and transmitter. rxd / txd xck rxd / txd xck inven = 0 inven = 1 sample sample table 18-2. inven and ucpha functionality spi mode inven ucpha leading edge trailing edge 0 0 0 rising, sample falling, setup 1 0 1 rising, setup falling, sample 2 1 0 falling, sample rising, setup 3 1 1 falling, setup rising, sample
204 8210b?avr?04/10 xmega d leading edge is the first clock edge in a clock cycl e. trailing edge is the last clock edge in a clock cycle. figure 18-4. ucpha and inven data transfer timing diagrams. 18.4 frame formats data transfer is frame based, where a serial frame consists of one character of data bits with synchronization bits (start and stop bits), and an optional parity bit for error checking. note that this does not apply to spi operation (see section 18.4.2 on page 205 ). the usart accepts all 30 combinations of the following as valid frame formats: ? 1 start bit ? 5, 6, 7, 8, or 9 data bits ? no, even or odd parity bit ? 1 or 2 stop bits a frame starts with the start bit followed by t he least significant data bi t and all data bits ending with the most significant bit. if enabled, the parity bit is inserted after the data bits, before the first stop bit. one frame can be directly followed by a start bit and a new frame, or the communication line can return to id le (high) state. figure 18-5 on page 204 illustrates the poss ible combinations of the frame formats. bits inside brackets are optional. figure 18-5. frame formats xck data setup (txd) data sample (rxd) xck data setup (txd) data sample (rxd) xck data setup (txd) data sample (rxd) xck data setup (txd) data sample (rxd) inven=0 inven=1 ucpha=0 ucpha=1 1 0 2 3 4 [5] [6] [7] [8] [p] st sp1 [sp2] (st / idle) (idle) frame
205 8210b?avr?04/10 xmega d 18.4.1 parity bit calculation even or odd parity can be selected for error checking. if even parity is selected, the parity bit is set to one if the number of data bits that is one is odd (making the total number of ones even). if odd parity is selected, the parity bit is set to one if the number of data bits that is one is even (making the total number of ones odd). 18.4.2 spi frame formats the serial frame in spi mode is defined to be one character of 8 data bits. the usart in master spi mode has two valid frame formats: ? 8-bit data with msb first ? 8-bit data with lsb first when a complete frame of 8 bits is transmitted, a new frame can directly follow it, or the commu- nication line returns to idle (high) state. 18.5 usart initialization usart initialization should use the following sequence: 1. set the txd pin value high, and optionally the xck pin low. 2. set the txd and optionally the xck pin as output. 3. set the baud rate and frame format. 4. set mode of operation (enables the xck pin output in synchronous mode). 5. enable the transmitter or the receiver depending on the usage. for interrupt driven usart operation, global interrupts should be disabled during the initialization. before doing a re-initialization with changed baud rate or frame format, be sure that there are no ongoing transmissions during the period the regi sters are changed. the transit and receive com- plete interrupt flags can be used to check that the transmitter has completed all transfers, and that there are no unread data in the receive buffer. 18.6 data transmission - the usart transmitter when the transmitter has been enabled, the normal port operation of the txd pin is overridden by the usart and given the function as the transmitter's serial output. the direction of the pin must be set as output using the direction register in the corresponding port. for details on port pin control refer to ?i/o ports? on page 101 . 18.6.1 sending frames a data transmission is initiated by loading the tr ansmit buffer (data) with the data to be sent. the data in the transmit buffer is moved to the shift register when the shift register is empty and ready to send a new frame. the shift register is loaded if it is in idle state (no ongoing table 1. st start bit, always low. (n) data bits (0 to 8). p parity bit. can be odd or even. sp stop bit, always high. idle no transfers on the communication line (rxd or txd). the idle state is always high.
206 8210b?avr?04/10 xmega d transmission) or immediately after the last stop bi t of the previous frame is transmitted. when the shift register is loade d with data, it will transfe r one comple te frame. the transmit complete interrupt flag (txcif) is set and the optional interrupt is generated when the entire frame in the shift register has been shifted out and there are no new data pres- ent in the transmit buffer. the transmit data register (data) can only be written when the data register empty flag (dreif) is set, indicating that the register is empty and ready for new data. when using frames with less than eight bits, the most significant bits written to the data are ignored. if 9-bit characters are used the ninth bit must be written to the txb8 bit before the low byte of the character is written to data. 18.6.2 disabling the transmitter a disabling of the transmitter w ill not become effective until on going and pending transmissions are completed, i.e. when the transmit shift register and transmit buffer register do not contain data to be transmitted. when transmitter is disabled it will no longer override the txdn pin and the pin direction is set as input. 18.7 data reception - the usart receiver when the receiver is enabled, the rxd pin is giv en the function as the receiver's serial input. the direction of the pin must be set as input, which is the default pin setting. 18.7.1 receiving frames the receiver starts data reception when it detects a valid start bit. each bit that follows the start bit will be sampled at the ba ud rate or xck clock, and shifted into the receive shift register until the first stop bit of a frame is received. a seco nd stop bit will be ignored by the receiver. when the first stop bit is received and a complete serial frame is present in the receive shift register, the contents of the shift register will be moved into the receive buffer. the receive complete interrupt flag (rxcif) is set, and the optional interrupt is generated. the receiver buffer can be read by reading the data register (data) location. data should not be read unless the receive complete interrupt flag is set. when using frames with less than eight bits, the unused most significant bits are read as zero. if 9-bit characters are used, the ninth bit must be read from the rxb8 bit before the low byte of the character is read from data. 18.7.2 receiver error flags the usart receiver has three error flags. the frame error (ferr), buffer overflow (bufovf) and parity error (perr) flags are accessible from the status register. the error flags are located in the receive fifo buffer together with their corresponding frame. due to the buffering of the error flags, the status register must be read before the receive buffer (data), since reading the data location changes the fifo buffer. 18.7.3 parity checker when enabled, the parity checker calculates the pa rity of the data bits in incoming frames and compares the result with the parity bit of the corresponding frame. if a parity error is detected the parity error flag is set.
207 8210b?avr?04/10 xmega d 18.7.4 disabling the receiver a disabling of the receiver will be immediate. the receiver buffer will be flushed, and data from ongoing receptions will be lost. 18.7.5 flushing the receive buffer if the receive buffer has to be flushed during normal operation, read the data location until the receive complete interr upt flags is cleared. 18.8 asynchronous data reception the usart includes a clock recovery and a data recovery unit for handling asynchronous data reception. the clock recovery logic is used for synchronizing the incoming asynchronous serial frames at the rxd pin to the internally generated baud rate clock. the data recovery logic sam- ples and low pass filters each incoming bit, ther eby improving the noise immunity of the receiver. the asynchronous reception operational range depends on the accuracy of the inter- nal baud rate clock, the rate of the incoming frames, and the frame size in number of bits. 18.8.1 asynchronous clock recovery the clock recovery logic synchronizes internal clock to the incoming serial frames. figure 18-6 on page 207 illustrates the sampling process of the start bit of an incoming frame. the sample rate is 16 times the baud rate for normal mode, and eight times the baud rate for double speed mode. the horizontal arrows illustrate the sy nchronization variation due to the sampling pro- cess. note the larger time variation when using the double speed mode of operation. samples denoted zero are samples done when the rxd li ne is idle, i.e. no co mmunication activity. figure 18-6. start bit sampling when the clock recovery logic detects a high (idle) to low (start) transition on the rxd line, the start bit detection sequence is initiated. sample 1 denotes the first zero-sample as shown in the figure. the clock recovery logic then uses samples 8, 9, and 10 for normal mode, and samples 4, 5, and 6 for double speed mode (indicated with sample numbers inside boxes on the figure) to decide if a valid start bit is received. if two or more of these three samples have a low level (the majority wins), the start bit is accepted. the clock recovery logic is synchronized and the data recovery can begin. if two or more of the three samples have a high level the start bit is rejected as a noise spike and the receiver starts looking for the next high to low-transition. the synchronization process is repeated for each start bit. 1234567 8 9 10 11 12 13 14 15 16 12 start idle 0 0 bit 0 3 123 4 5 678 12 0 rxd sample (u2x = 0) sample (u2x = 1)
208 8210b?avr?04/10 xmega d 18.8.2 asynchronous data recovery the data recovery unit uses sixteen samples in normal mode and eight samples in double speed mode for each bit. figure 18-7 on page 208 shows the sampling process of data and par- ity bits. figure 18-7. sampling of data and parity bit as for start bit detection, identical majority voting technique is used on the three center samples (indicated with sample numbers inside boxes) for deciding of the logic level of the received bit. this majority voting process acts as a low pass f ilter for the received signal on the rxd pin. the process is repeated for each bit until a complete frame is received. including the first, but exclud- ing additional stop bits. if the stop bit sampled has a logic 0 value, the frame error (ferr) flag will be set. figure 18-8 on page 208 shows the sampling of the stop bit in relation to the earliest possible beginning of the next frame's start bit. figure 18-8. stop bit sampling and ne xt start bit sampling a new high to low transition indicating the start bit of a new frame can come right after the last of the bits used for majority voting. for normal speed mode, the first low level sample can be at point marked (a) in stop bit sampling and next start bit sampling. for double speed mode the first low level must be delayed to (b). (c) marks a stop bit of full length at nominal baud rate. the early start bit detection influences the operational range of the receiver. 18.8.3 asynchronous operational range the operational range of the receiver is dependent on the mismatch between the received bit rate and the internally generated baud rate. if an external transmitter is sending on bit rates that are too fast or too slow, or the internally generated baud rate of the receiver does not match the external source?s base frequency, the receiver will not be able to synchroni ze the frames to the start bit. 1234567 8 9 10 11 12 13 14 15 16 1 bit n 123 4 5 678 1 rxd sample (clk2x = 0) sample (clk2x = 1) 1234567 8 9 10 0/1 0/1 0/1 stop 1 123 4 5 60/1 rxd sample (clk2x = 0) sample (clk2x = 1) (a) (b) (c)
209 8210b?avr?04/10 xmega d the following equations can be used to calculate the ratio of the incoming data rate and internal receiver baud rate. table 18-3 and table 18-4 on page 209 list the maximum receiver baud rate error that can be tolerated. normal speed mode has higher toleration of baud rate variations. table 1. table 1. d sum of character size and parity size (d = 5 to 10 bit). s samples per bit. s = 16 for normal speed mode and s = 8 for double speed mode. s f first sample number used for majority voting. s f = 8 for normal speed and s f = 4 for double speed mode. s m middle sample number used for majority voting. s m = 9 for normal speed and s m = 5 for double speed mode. r slow is the ratio of the slowest incoming data rate that can be accepted in relation to the receiver baud rate. r fast is the ratio of the fastest incoming data ra te that can be accepted in relation to the receiver baud rate. table 18-3. recommended maximum receiver baud rate error for normal speed mode (clk2x = 0) d #(data + parity bit) r slow (%) r fast (%) max total error (%) recommended max receiver error (%) 5 93.20 106.67 +6.67/-6.80 3.0 6 94.12 105.79 +5.79/-5.88 2.5 7 94.81 105.11 +5.11/-5.19 2.0 8 95.36 104.58 +4.58/-4.54 2.0 9 95.81 104.14 +4.14/-4.19 1.5 10 96.17 103.78 +3.78/-3.83 1.5 table 18-4. recommended maximum receiver baud rate error for double speed mode (clk2x = 1) d #(data + parity bit) r slow (%) r fast (%) max total error (%) recommended max receiver error (%) 5 94.12 105.66 +5.66/-5.88 2.5 6 94.92 104.92 +4.92/-5.08 2.0 7 95.52 104.35 +4.35/-4.48 1.5 r slow d 1 + () s s 1 ? ds ? s f ++ ------------------------------------------ - = r fast d 2 + () s d 1 + () ss m + ----------------------------------- =
210 8210b?avr?04/10 xmega d the recommendations of the maximum receiver baud rate error was made under the assump- tion that the receiver and transmitter equally divides the maximum total error. there are two possible sources for the receivers baud rate error. the receiver's system clock will always have some minor instability. in addition, the baud rate generator can not always do an exact division of the peripheral clock frequency to get the baud rate wanted. in this case the bsel and bscale value should be selected to give the lowe st possible error. 18.9 the impact of fractional baud rate generation fractional baud rate generation is possible for asynchronous operation due to the relatively high number of clock cycles (i.e. samples) for each frame. each bit is sampled sixteen times, but only the center samples are of importance. this leaves some slack for each bit. not only that, but the total number of samples for one frame is also relatively high. given a 1-start, 8-data, no-parity, and 1-stop bit frame format, and assumes that normal speed mode is used, the total number of samples for a frame is, (1+8+1)*16, or 160. as earlier stated, the uart can tolerate plus minus some samples. the critical factor is the time from the falling edge of the start bit (i.e. the clock synchronization) to the last bit's (i.e. the first stop bit) value is recovered. standard baud rate generators have the unwanted property of having large frequency steps between high baud rate settings. worst case is found between bsel value 0x000 and 0x001. going from an bsel value of 0x000 for which has a 10-bit frame of 160 samples, to an bsel value 0x001 with 320 samples, shows a 50% change in frequency. however, when increasing the bsel values the step change will quickly decreas e. ideally the step size should be small even between the fastest baud rates. this is wh ere the advantage of the fractional baud rate generator emerges. in principle the fractional baud rate generator works by doing uneven counting and distributing the error evenly over the entire frame. a typical count sequence for an ordinary baud rate gener- ator is: 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, ? which has an even period time. a baud rate clock tick each time the counter reaches zero, and a sample of the received signal on rxd is taken for each baud rate clock tick. for the fractional baud rate generator the count sequence can have an uneven period: 2, 1, 0, 3, 2, 1, 0, 2, 1, 0, 3, 2, ? in this example an extra cycle is added every se cond cycle. this gives a baud rate clock tick jit- ter, but the average period has been increased by a fraction, more prec isely 0.5 clock cycles. the impact of the fractional baud rate generation is that the step size between baud rate settings has been reduced. given a scale factor of -1 the worst-case step, then becomes from 160 to 240 8 96.00 103.90 +3.90/-4.00 1.5 9 96.39 103.53 +3.53/-3.61 1.5 10 96.70 103.23 +3.23/-3.30 1.0 table 18-4. recommended maximum receiver baud rate error for double speed mode (clk2x = 1) (continued) d #(data + parity bit) r slow (%) r fast (%) max total error (%) recommended max receiver error (%)
211 8210b?avr?04/10 xmega d samples per 10-bit frame compared to the previous from 160 to 320. higher negative scale fac- tor gives even finer granularity. there is a limit to how high the scale factor can be. a rule of thumb is that the value 2 bscale must be at least half of the minimum number of clock cycles a frame takes. for instance for 10-bit frames t he minimum number of clo ck cycles is 160. this means that the highest applicable scale factor is -6 (2 -6 = 64 < 160/2 = 80). for higher bsel set- tings the scale factor can be increased. 18.10 usart in m aster spi mode using the usart in master spi mode (mspim) requires the transmitter to be enabled. the receiver can optionally be enabl ed to serve as the serial input. the xck pin will be used as the transfer clock. as for usart a data transfer is initiated by writin g to the data location. this is the case for both sending and receiving data since the transmitter c ontrols the transfer clock. the data written to data is moved from the transmit buffer to the shift register when the shift register is ready to send a new frame. the transmitter and receiver interrupt flags and corresponding usart interrupts in master spi mode are identical in function to the normal u sart operation. the receiver error status flags are not in use and is always read as zero. disabling of the usart transmitter or receiver in master spi mode is identical in function to the normal usart operation. 18.11 usart spi vs. spi the usart in master spi mode is fu lly compatible with the spi regarding: ? master mode timing diagram. ? the ucpha bit functionality is identical to the spi cpha bit. ? the udord bit functionality is identical to the spi dord bit. since the usart in master spi mode reuses the usart resources, the use of the usart in mspim is somewhat different compared to the xmega spi module. in addition to differences of the control register bits and no spi slave support, the following features differ between the two modules: ? the transmitter usart in master spi mode includes buffering. the xmega spi has no transmit buffer. ? the receiver in usart in master spi includes an additional buffer level. ? the spi wcol (write collision) bit is no t included in usart in master spi mode. ? the spi double speed mode (spi2x) bit is not included. however, the same effect is achieved by setting bsel accordingly. ? interrupt timing is not compatible. ? pin control differs due to the master only operation of the usart in master spi mode.
212 8210b?avr?04/10 xmega d a comparison of the usart in master spi mode and the spi pins is shown table 18-5 . 18.12 multi-processor communication mode enabling the multi-processor communication mode (mpcm) effectively reduces the number of incoming frames that has to be handled by th e receiver in a system with multiple mcus com- municating via the same serial bus. in this mode a dedicated bit in the frames is used to indicate whether the frame is an address or data frame. if the receiver is set up to receive frames that contain 5 to 8 data bits, the first stop bit is used to indicate the frame type. if the receiver is set up for frames with 9 data bits, the ninth bit is used. when the frame type bit is one, the frame contains an address. when the frame type bit is zero, the frame is a data frame. the transmitter is unaffected by the mpcm setting, but if 5- to 8-bit character frames are used, the transmitter must be set to use two stop bit since the first stop bit is used for indicating the frame type. if a particular slave mcu has be en addressed, it will receive th e following data frames as nor- mal, while the other slave mcus will ignore the received frames until another address frame is received. 18.12.1 using multi-processor communication mode for an mcu to act as a master mcu, it should use a 9-bit character frame format. the ninth bit must be set when an address frame is being transmitted and cleared when a data frame is being transmitted. the slave mcus must in this case be set to use a 9-bit character frame format. the following procedure should be used to exchange data in multi-processor communication mode: 1. all slave mcus are in multi- processor communication mode. 2. the master mcu sends an address frame, and all slaves receive and read this frame. 3. each slave mcu determines if it has been selected. 4. the addressed mcu will disable mpcm and re ceive all data frames. the other slave mcus will ignore the data frames. 5. when the addressed mcu has received the last data frame, it must enable mpcm again and wait for new address frame from the master. the process then repeats from 2. using any of the 5- to 8-bit character frame formats is possible, but impractical since the receiver must change between using n and n+1 character frame formats. this makes full duplex operation difficult since the transmitte r and receiver uses the same character size setting. table 18-5. comparison of usart in master spi mode and spi pins. usart spi comment txd mosi master out only rxd miso master in only xck sck functionally identical n/a ss not supported by usart in master spi
213 8210b?avr?04/10 xmega d 18.13 ircom mode of operation ircom mode can be enabled to use the ircom module with the usart. this enables irda 1.4 physical compliant modulation and demodulation for baud rates up to 115.2 kbps. when ircom mode is enabled, double transmission speed cannot be used for the usart. for devices with more than one usart, ircom mode can only be enabled for one usart at a time. for details refer to ?ircom - ir communication module? on page 220 . 18.14 register description 18.14.1 data - usart i/o data register the usart transmit data buffer register and usart receive data buffer registers share the same i/o address referred to as usart data register (data). the transmit data buffer reg- ister (txb) will be the destination for data written to the data register location. reading the data register location will retu rn the contents of the receiv e data buffer register (rxb). for 5-, 6-, or 7-bit char acters the upper unu sed bits will be ignored by the transmitter and set to zero by the receiver. the transmit buffer can only be written when the dreif flag in the status register is set. data written to data when the dreif flag is not set, will be ignored by the usart transmitter. when data is written to the transmit buffer, and the transmitter is enabled, the transmitter will load the data into the transmit shift register when the shift register is empty. the data is then transmitted on the txd pin. the receive buffer consists of a two level fifo. the fifo and the corresponding flags in the status register (status) will change state whenever the receive buffer is accessed (read). always read status before data in order to get the correct flags. 18.14.2 status - usart status register ? bit 7 - rxcif: usart receive complete interrupt flag this flag is set when there are unread data in the receive buffer and cleared when the receive buffer is empty (i.e., does not contain any unread data). when the receiver is disabled, the receive buffer will be fl ushed and consequently the rxcif will become zero. when interrupt-driven data reception is used, the receive complete interrupt routine must read the received data from data in order to clear the rxcif. if not, a new interrupt will occur directly after the return from the current interrupt. this flag can also be cleared by writing a one to its bit location. bit 76543210 +0x00 rxb[[7:0] txb[[7:0] read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x01 rxcif txcif dreif ferr bufovf perr ?rxb8status read/writerr/wrrrrrr/w initial value00100000
214 8210b?avr?04/10 xmega d ? bit 6 - txcif: usart transmit complete interrupt flag this flag is set when the entire frame in the transmit shift register has been shifted out and there are no new data in the transmit buffer (data). the txcif is automatically cleared when the transmit complete interrupt vector is executed. the flag can also be cleared by writing a one to its bit location. ? bit 5 - dreif: usart data register empty flag the dreif indicates if the transmit buffer (data) is ready to receive new data. the flag is one when the transmit buffer is empty, and zero when the transmit buffer contains data to be trans- mitted that has not yet been moved into the shift register. dreif is set after a reset to indicate that the transmitter is ready. always write this bit to zero when writin g the status register. dreif is cleared by writing data. when interrupt-driven data transmission is used, the data register empty interrupt routine must either wr ite new data to data in order to clear dreif or disable the data register empty interrupt. if not, a new interrupt will occur directly after the return from the current interrupt. ? bit 4 - ferr: frame error the ferr flag indicates the state of the first stop bit of the next readable frame stored in the receive buffer. the bit is set if the received character had a frame error, i.e. when the first stop bit was zero, and cleared when the stop bit of the received data is one. this bit is valid until the receive buffer (data) is read. the ferr is not affected by setting the sbmode bit in ctrlc since the receiver ignores all, except for the first stop bit. always write this bit location to zero when writing the status register. this flag is not used in master spi mode of operation. ? bit 3 - bufovf: buffer overflow the bufovf flag indicates data loss due to a receiver buffer full condition. this flag is set if a buffer overflow condition is detected. a buffer overflow occurs when the receive buffer is full (two characters), it is a new ch aracter waiting in the receive shift register, and a new start bit is detected. this flag is valid until the receive buffer (data) is read. always write this bit location to zero when writing the status register. this flag is not used in master spi mode of operation. ? bit 2 - perr: parity error if parity checking is enabled and the next character in the receive buffer has a parity error this flag is set. if parity check is not enabled the perr will always be read as zero. this bit is valid until the receive buffer (data) is read. always write this bit location to zero when writing the status register. for details on parity calculation refer to ?parity bit calculation? on page 205 . this flag is not used in master spi mode of operation. ? bit 1 - reserved this bit is reserved and will a lways be read as zero. for compat ibility with future devices, always write this bit to zero when this register is written. ? bit 0 - rxb8: receive bit 8 rxb8 is the ninth data bit of the received charac ter when operating with serial frames with nine data bits. when used, this bit must be read before reading the low bits from data.
215 8210b?avr?04/10 xmega d this bit is unused in master spi mode of operation. 18.14.3 ctrla ? usart control register a ? bit 7:6 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 5:4 - rxcintlvl[1:0]: receive complete interrupt level these bits enable the receive complete interrup t and select the interrupt level as described in ?interrupts and programmable multi-level interrupt controller? on page 95 . the enabled interrupt will be triggered when the rxcif in the status register is set. ? bit 3:2 - txcintlvl[1:0]: transmit complete interrupt level these bits enable the transmit complete interrupt and select the interrupt level as described in ?interrupts and programmable multi-level interrupt controller? on page 95 . the enabled interrupt will be triggered when the txcif in the status register is set. ? bit 1:0 - dreintlvl[1:0]: usart data register empty interrupt level these bits enable the data register empty inte rrupt and select the interrupt level as described in ?interrupts and programmable multi-level interrupt controller? on page 95 . the enabled inter- rupt will be triggered when the drei f in the status register is set. 18.14.4 ctrlb - usart control register b ? bit 7:5 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 4 - rxen: receiver enable writing this bit to one enables the usart receiv er. the receiver will override normal port oper- ation for the rxd pin when enabled. disabling the receiver will flush the receive buffer invalidating the ferr, bufovf, and perr flags. ? bit 3 - txen: transmitter enable writing this bit to one enables the usart tr ansmitter. the transmitter will override normal port operation for the txd pin when enabled. disabling the transmitter (writing txen to zero) will not bit 76543210 +0x03 ? ? rxcintlvl[1:0] txcintlvl[1:0] dreintlvl[1:0] ctrla read/write r r r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x04 ? ? ? rxen txen clk2x mpcm txb8 ctrlb read/write r r r r/w r/w r/w r/w r/w initial value00000000
216 8210b?avr?04/10 xmega d become effective until ongoing and pending transmissions are completed, i.e., when the trans- mit shift register and transmit buffer register do not contain data to be transmitted. when disabled, the transmitter will no longer override the txd port. ? bit 2 - clk2x: double transmission speed writing this bit to one will reduce the divisor of the baud rate divider from 16 to 8 effectively dou- bling the transfer rate for asynchronous co mmunication modes. for synchronous operation this bit has no effect and should always be written to zero. this bit must be zero when the usart communication mode is configured to ircom. this bit is unused in master spi mode of operation. ? bit 1 - mpcm: multi-processor communication mode this bit enables the multi-processor communication mode. when the mpcm bit is written to one, the usart receiver ignores all the incoming frames that do not contain address informa- tion. the transmitter is unaffected by the mpcm setting. for more detailed information see ?multi-processor communication mode? on page 212 . this bit is unused in master spi mode of operation. ? bit 0 - txb8: transmit bit 8 txb8 is the ninth data bit in the character to be transmitted when operating with serial frames with nine data bits. when used this bit must be written before writing the low bits to data. this bit is unused in master spi mode of operation. 18.14.5 ctrlc - usart control register c note: 1. master spi mode ? bits 7:6 - cmode[1:0]: usart communication mode these bits select the mode of oper ation of the usart as shown in table 18-6 . bit76543210 +0x05 cmode[1:0] pmode[1:0] sbmode chsize[2:0] +0x05 (1) cmode[1:0] ? ? ? udord ucpha ? read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 1 1 0 table 18-6. cmode bit settings cmode[1:0] group configuration mode 00 asynchronous asynchronous usart 01 synchronous synchronous usart 10 ircom ircom (1) 1. see ?ircom - ir communication module? on page 220 for full description on using ircom mode. 11 mspi master spi (2) 2. see ?usart? on page 199 for full description of the ma ster spi mode (mspim) operation
217 8210b?avr?04/10 xmega d ? bits 5:4 - pmode[1:0]: parity mode these bits enable and set the type of parity generation according to table 18-7 on page 217 . when enabled, the transmitter will au tomatically generate and send the parity of the transmitted data bits within each frame. th e receiver will generate a parity value for the incoming data and compare it to the pmode setting and if a mismatch is detected, the perr flag in status will be set. these bits are unused in master spi mode of operation. ? bit 3 - sbmode: stop bit mode this bit selects the number of stop bits to be inserted by the transmitter according to table 18-8 on page 217 . the receiver ignores this setting. this bit is unused in master spi mode of operation. ? bit 2:0 - chsize[2:0]: character size the chsize[2:0] bits sets the number of data bits in a frame according to table 18-9 on page 217 . the receiver and transmitter use the same setting. table 18-7. pmode bits settings pmode[1:0] group configuration parity mode 00 disabled disabled 01 reserved 10 even enabled, even parity 11 odd enabled, odd parity table 18-8. sbmode bit settings sbmode stop bit(s) 01-bit 12-bit table 18-9. chsize bits settings chsize[2:0] group configuration character size 000 5bit 5-bit 001 6bit 6-bit 010 7bit 7-bit 011 8bit 8-bit 100 reserved 101 reserved 110 reserved 111 9bit 9-bit
218 8210b?avr?04/10 xmega d ? bit 2 - udord: data order this bit sets the frame format. when written to one the lsb of the data word is transmitted first. when written to zero the msb of the data word is transmitted first. the receiver and transmitter use the same setting. c hanging the setting of udord will co rrupt all ongoing communication for both receiver and transmitter. ? bit 1 - ucpha: clock phase the ucpha bit setting determine if data is samp led on the leading (first) edge or tailing (last) edge of xckn. refer to the ?spi clock generation? on page 203 for details. 18.14.6 baudctrla - usar t baud rate register ? bit 7:0 - bsel[7:0]: usart baud rate register this is a 12-bit value which contains the us art baud rate setting. the baudctrlb contains the four most significan t bits, and the baudctrla contains the eight least significant bits of the usart baud rate. ongoing transmissions by the transmitter and receiver will be corrupted if the baud rate is changed. writing baudctrla will trigger an immediate u pdate of the baud rate prescaler. 18.14.7 baudctrlb - usar t baud rate register ? bit 7:4 - bscale[3:0]: usart baud rate scale factor these bits select the baud rate generator scale factor. the scale factor is given in two's com- plement form from -7 (0b1001) to 7 (0b0111). the -8 (0b1000) setting is reserved. for positive scale values the baud rate generator is prescaled by 2 bscale . for negative values the baud rate generator will use fractional counting, wh ich increases the resolution. see equations in table 18-1 on page 202 . ? bit 3:0 - bsel[3:0]: usart baud rate register this is a 12-bit value which contains the us art baud rate setting. the baudctrlb contains the four most significan t bits, and the baudctrla contains the eight least significant bits of the usart baud rate. ongoing transmissions by the transmitter and receiver will be corrupted if the baud rate is changed. writing baudctrla will trigger an immediate u pdate of the baud rate prescaler. bit 76543210 +0x06 bsel[7:0] baudctrla read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x07 bscale[3:0] bsel[11:8] baudctrlb read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
219 8210b?avr?04/10 xmega d 18.15 register summary 18.15.1 register description - usart 18.15.2 register description - usart in master spi mode 18.16 interrupt vector summary address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 data data[7:0] 213 +0x01 status rxcif txcif dreif ferr bufovf perr ? rxb8 213 +0x02 reserved ? ? ? ? ? ? ? ? +0x03 ctrla ? ? rxcintlvl[1:0] txcintlvl[1:0] dreintlvl[1:0] 215 +0x04 ctrlb ? ? ? rxen txen clk2x mpcm txb8 215 +0x05 ctrlc cmode[1:0] pmode[1:0] sbmode chsize[2:0] 217 +0x06 baudctrla bsel[7:0] 219 +0x07 baudctrlb bscale[3:0] bsel[11:8] 218 address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 data data[7:0] 213 +0x01 status rxcif txcif dreif ? ? ? ? ?213 +0x02 reserved ? ? ? ? ? ? ? ? +0x03 ctrla ? ? rxcintlvl[1:0] txcintlvl[1:0] dreintlvl[1:0] 215 +0x04 ctrlb ? ? ?rxentxen ? ? ?215 +0x05 ctrlc cmode[1:0] ? ? ? udord ucph ?216 +0x06 baudctrla bsel[7:0] 218 +0x07 baudctrlb bscale[3:0] bsel[11:8] 218 table 18-10. usart interrupt vectors and their word offset address offset source interrupt description 0x00 rxc_vect usart receive complete interrupt vector 0x02 dre_vect usart data register empty interrupt vector 0x04 txc_vect usart transmit complete interrupt vector
220 8210b?avr?04/10 xmega d 19. ircom - ir communication module 19.1 features ? pulse modulation/demodulation for infrared communication ? irda 1.4 compatible for baud rates up to 115.2 kbps ? selectable pulse modulation scheme ? 3/16 of baud rate period ? fixed pulse period, 8-bit programmable ? pulse modulation disabled ? built in filtering ? can be connected to and used by any usart 19.2 overview xmega contains an infrared communication module (ircom) irda 1.4 compatible module for baud rates up to 115.2 kbps. this supports three modulation schemes: 3/16 of baud rate period, fixed programmable pulse time based on the peripheral clock speed, or pulse modulation dis- abled. there is one ircom available, and th is can be connected to any usart to enable infrared pulse coding/decoding for that usart. figure 19-1. ircom connection to usarts and associated port pins the ircom is automatically enab led when a usart is set in ircom mode. when this is done signals between the usart and the rx/tx pins are routed through the module as shown in fig- ure 19-1 on page 220 . it is also possible to select an ev ent channel from the event system as input for the ircom receiver. this will di sable the rx input from the usart pin. ircom pulse decoding dif event system rxdnx txdnx usartxn .... usartd0 usartc0 rxdd0 txdd0 rxdc0 txdc0 pulse encoding decoded rxd encoded txd encoded rxd rxd... txd... decoded txd events
221 8210b?avr?04/10 xmega d for transmission, three pulse modulation schemes are available: ? 3/16 of baud rate period. ? fixed programmable pulse time based on the peripheral clock speed. ? pulse modulation disabled. for reception, a minimum high-level pulse width for the pulse to be decoded as a logical 0 can be selected. shorter pulses will then be discarded and the bit will be decoded to logical 1 as if no pulse where received. one ircom will be available for use with any u sart in the device. th e module can only be used in combination with one usart at a time, thus ircom mode must not be set for more than one usart at a time. this must be ensured in the user software. 19.2.1 event system filtering the event system can be used as the receiver input. this enables ircom or usart input from other i/o pins or sources than the corresponding rx pin. if event system input is enabled, input from the usart's rx pin is automatically disa bled. the event system has digital input filter (dif) on the event channels, that can be used for filtering. refer to section 6. ?event system? on page 65 ? for details on using the event system.
222 8210b?avr?04/10 xmega d 19.3 registers description 19.3.1 txplctrl - ircom transmitter pulse length control register ? bits 7:0 - txplctrl[7:0] - transmitter pulse length control the 8-bit value sets the pulse modulation scheme for the transmitter. setting this register will have no effect if ircom mode is not selected by a usart. by leaving this register value to zero, 3/16 of baud rate period pulse modulation is used. setting this value from 1 to 254 will give a fixed pulse length coding. the 8-bit value sets the number of system clock periods for the pulse. the start of the pulse will be synchronized with the rising edge of the baud rate clock. setting the value to 255 (0xff) will disable pul se coding, letting the rx and tx signals pass through the ircom module unaltered. this enables other features through the ircom module, such as half-duplex usart, loop-back testing and usart rx input from an event channel. note: txpctrl must be configured before usart transmitter is enabled (txen). 19.3.2 rxplctrl - ircom receiver pulse length control register ? bits 7:0 - rxplctrl[7:0] - receiver pulse length control the 8-bit value sets the filter coefficient for the ircom transceiv er. setting this register will have no effect if ircom mode is not selected by a usart. by leaving this register value to zero, filtering is disabled. setting this value between 1 and 255 will enable filtering, where x+ 1 equal samples is required fo r the pulse to be accepted. note: rxpctrl must be configured before usart receiver is enabled (rxen). 19.3.3 ctrl - ircom control register ? bits 7:4 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. bit 76543210 +0x00 txplctrl[7:0] txplctrl read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 00000000 bit 76543210 +0x00 rxplctrl[7:0] rxplctrl read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x00 ? ? ? ? evsel[3:0] ctrl read/write r r r r r/w r/w r/w r/w initial value 00000000
223 8210b?avr?04/10 xmega d ? bits 3:0 - evsel [3:0]: event channel selection these bits select the event channel source for the ircom receiver, according to table 19-1 on page 223 . if event input is selected for the ircom receiver, the input from the usart?s rx pin is automatically disabled. 19.4 register summary table 19-1. event channel select evsel[3:0] group configuration event source 0000 none 0001 (reserved) 0010 (reserved) 0011 (reserved) 0100 (reserved) 0101 (reserved) 0110 (reserved) 0111 (reserved) 1xxx chn event system channelx; x = {0, ?,3} address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 txplctrl txplctrl[7:0] 222 +0x00 rxplctrl rxplctrl[7:0] 222 +0x00 ctrl ? ? ? ? evsel[3:0] 222
224 8210b?avr?04/10 xmega d 20. adc - analog to digital converter 20.1 features ? 12-bit resolution ? up to 200 ksps conversion rate ? single-ended or diff erential measurements ? signed and un signed mode ? 8 - 16 single-ended inputs ? 8x4 differential inputs without gain ? 8x4 differential input with gain ? 3 internal inputs ? temperature sensor ? vcc voltage divided by 10 ? bandgap voltage ? 1x, 2x, 4x, 8x, 16x, 32x or 64x software selectable gain ? 8-, or 12-bit selectable resolution ? minimum single result propagation de lay of 4.25s with 8-bit resolution ? minimum single result propagation de lay of 5.0s with 12-bit resolution ? built-in accurate reference ? optional external reference ? optional event triggered co nversion for accurate timing ? optional interrupt/even t on compare result 20.2 overview the adc converts analog voltages to digital values. the adc has 12-bit resolution and is capa- ble of converting up to 200k samples per second. the input selection is flexible, and both single- ended and differential measurements can be done. for differential measurements an optional gain stage is available to increase the dynamic range. in addition several internal signal inputs are available. the adc can provide both signed and unsigned results. adc measurements can either be started by application software or an incoming event from another peripheral in the device. the latter ensure the adc measurements can be started with predictable timing, and without software intervention. the adc has one channel, meaning there is one input selection (mux selection) and one result register available. both internal and external analog reference voltages can be used. a very accurate internal 1.00v reference is available. an integrated temperature sensor is available and the output from this can be measured with the adc. a vcc/10 signal and the bandgap voltage can also be measured by the adc.
225 8210b?avr?04/10 xmega d figure 20-1. adc overview 20.3 input sources the input sources for the adc are the analog voltage inputs that the adc can measure and convert. four types of measurements can be selected: ? differential input ? differential input with gain ? single ended input ? internal input the analog input pins are used for single ended and differential input, while the internal inputs are directly available inside the device. both porta and portb analog pins can then be used as input for the adc. the mux control register select which input that is converted and the type of measurements in one operation. the four types of measurement s and their corresponding mux selections are shown in figure 20-2 on page 226 to figure 20-6 on page 228 . the adc itself is always different ial, also for single ended inputs where the negative input for the adc will be connected to an fixed internal value. 20.3.1 differential input when differential input is sele cted all analog input pins can be se lected as positive input, and analog input pins 0 to 3 can be selected as negative input. the adc must be set in signed mode when differential input is used. adc result register pin inputs differential pin inputs 1-64 x internal inputs mux selection event triggers configuration reference selection
226 8210b?avr?04/10 xmega d figure 20-2. differential measurement 20.3.2 differential input with gain when differential input with gain is selected al l analog input pins can be selected as positive input, and analog input pins 4 to 7 can be selected as negative input. when the gain stage is used, the differential analog input is first sa mpled and amplified by the gain stage before the result is fed into the adc. the adc must be set in signed mode when differential input with gain is used. the gain is selectable to 1x, 2x, 4x, 8x, 16x, 32 x and 64x gain. in addition a 1/2x (divide by two) setting is available, enabling measurement of differential input of up to 2x the reference voltage. figure 20-3. differential measurement with gain 20.3.3 single ended input for single ended measurements all analog input pins can be used as input. single ended mea- surements can be done in both signed and unsigned mode. adc adc0 adc1 adc2 adc3 ... ... adc14 adc15 + - adc0 adc1 adc2 adc3 adc adc0 adc1 adc2 adc3 ... ... adc14 adc15 + adc4 adc5 adc6 adc7 - 1-64 x
227 8210b?avr?04/10 xmega d the negative input is connected to internal ground in signed mode. figure 20-4. single-ended measurement in signed mode in unsigned mode the negative input is connected to half of the voltage reference (vref) volt- age minus a fixed offset. the nominal value for the offset is: since the adc is differential, unsigned mode is ac hieved by dividing the reference by two inter- nally, resulting in an input range from vref to zero for the positive single ended input. the offset enables the adc to measure zero cross detection in unsigned mode, and to calibrate any positive offset where the internal ground in the device is higher than the external ground. see figure 20-11 on page 230 for details. figure 20-5. single ended measurement in unsigned mode 20.3.4 internal inputs three internal analog signals can be se lected as input and measured by the adc. ? temperature sensor ? bandgap voltage ?v cc scaled the voltage output from an internal temperature reference can be measured with the adc and the voltage output will give an a dc result representing the curren t temperature in the microcon- troller. during production test, the adc measures a fixed temperature using the internal temperature sensor, and the value is store in the production calibration row and can be used for temperature sensor calibration. the bandgap voltage is an accurate voltage reference inside the microcontroller that is the source for other internal voltage references. adc adc0 adc1 adc2 adc3 ... ... adc14 adc15 + - v vref 0.05 = adc adc0 adc1 adc2 adc3 adc... ... adc14 adc15 v vref ? 2 + -
228 8210b?avr?04/10 xmega d v cc can be measured directly by scaling it down and dividing it by 10 before the adc input. thus, v cc of 1.8 v will be measured as 0.18 v and v cc of 3.6 v will be measured as 0.36 v. some of the internal signals need to be turned on before they can be used measured. refer to the manual for these modules for details of how to turn them on. the sample rate for the internal signals is lower than the maximum speed for the adc, refer to the adc characteristics in the device datasheets for details on sample rate of the internal signals. when measuring the internal signals, the negat ive input is connected to internal ground in signed mode. figure 20-6. internal measurements in signed mode in unsigned mode the negative input is connected to a fixed value which is half of the voltage ref- erence (vref) minus a fixed offset as it is for single ended unsigned input. refer to figure 20- 11 on page 230 for details. figure 20-7. internal measurements in unsigned mode adc temp ref vcc scaled bandgap ref + - adc temp ref vcc scaled bandgap ref + - v vref ? 2
229 8210b?avr?04/10 xmega d 20.4 voltage reference selection the following voltages can be used as the voltage reference (vref) for the adc: ? accurate internal 1.00 v voltage. ? internal v cc /1.6 voltage. ? external voltage applied to aref pin on porta. ? external voltage applied to aref pin on portb. figure 20-8. adc voltage reference selection 20.5 conversion result the adc can be set up to be either in signed or in unsigned mode. in signed mode, both negative and positive voltages can be measured, both for single ended and differential input. with 12-bit resolution, the top value of a signed result is 2047 and the results will be in the range -2048 to +2047 (0xf800 - 0x07ff). in unsigned mode the top value is 4095 and results will be in the range 0 - 4095 (0 - 0x0fff). signed mode must be used when any of the adc inputs are set up for differential measure- ments. in unsigned mode only single ende d or internal signals can be measured. the result of the analog to digital conversi on is written to the result registers, res. in signed mode the adc transfer function can be written as: vinp and vinn are the positive and negative inputs to the adc. gain is 1 unless differential measurement with gain is used. in unsigned mode the adc transfer functions can be written as: vinp is the single ended or internal input. the application software selects if an 8- or 12-bit result should be generated. a result with lower resolution will be ava ilable faster. see the ?adc clock and conversion timing? on page 231 for a description on how to calculate the propagation delay for. the result register is 16-bit. an 8-bit result is always represented right adjusted in the 16-bit result registers. right adjusted means that the 8 lsb is found in the low byte. a 12-bit result can internal 1.00v arefb arefa internal vcc/1.6 vref res vinp - vinn vref --------------------------------- gain top ?? = res vinp - (- v ) vref --------------------------------- - top ? =
230 8210b?avr?04/10 xmega d be represented both left- or right adjusted. left adjusted means that the 8 msb are found in the high byte. when the adc is in signed mode, the msb repres ents the sign bit. in 12-bit right adjusted mode, the sign bit (bit 11) is padded to bits 12-15 to create a signed 16-bit number directly. in 8-bit mode, the sign bit (bit 7) is padded to the entire high byte. figure 20-9 on page 230 to figure 20-11 on page 230 shows the different input options, the sig- nal input range and the result representation with 12-bit right adjusted mode. figure 20-9. signed differential input (with gain), input range, and result representation figure 20-10. signed single ended and internal input, input range, and result representation figure 20-11. unsigned single ended and internal input, input range, and result representation 2047 2046 2045 ... 3 2 1 0 -1 ... -2045 -2046 -2047 -2048 7ff 7fe 7fd ... 3 2 1 0 fff ffe ... 803 802 801 800 dec hex 0111 1111 1111 0111 1111 1110 0111 1111 1101 ... 0000 0000 0011 0000 0000 0010 0000 0000 0001 0000 0000 0000 1111 1111 1111 1111 1111 1110 ... 1000 0000 0011 1000 0000 0010 1000 0000 0001 1000 0000 0000 binary 0000 0111 1111 1111 0000 0111 1111 1110 0000 0111 1111 1101 ... 0000 0000 0000 0011 0000 0000 0000 0010 0000 0000 0000 0001 0000 0000 0000 0000 1111 1111 1111 1111 1111 1111 1111 1110 ... 1111 1000 0000 0011 1111 1000 0000 0010 1111 1000 0000 0001 1111 1000 0000 0000 16-bit result register vref gain -vref gain 0 v vinn res vinp -2 2047 2046 2045 ... 3 2 1 0 -1 -2 ... -2045 -2046 -2047 -2048 7ff 7fe 7fd ... 3 2 1 0 fff ffe ... 803 802 801 800 dec hex 0111 1111 1111 0111 1111 1110 0111 1111 1101 ... 0000 0000 0011 0000 0000 0010 0000 0000 0001 0000 0000 0000 1111 1111 1111 1111 1111 1110 ... 1000 0000 0011 1000 0000 0010 1000 0000 0001 1000 0000 0000 binary 0000 0111 1111 1111 0000 0111 1111 1110 0000 0111 1111 1101 ... 0000 0000 0000 0011 0000 0000 0000 0010 0000 0000 0000 0001 0000 0000 0000 0000 1111 1111 1111 1111 1111 1111 1111 1110 ... 1111 1000 0000 0011 1111 1000 0000 0010 1111 1000 0000 0001 1111 1000 0000 0000 16-bit result register vref -vref 0 v vinp vinn = gnd 4095 4094 4093 ... 203 202 201 200 fff ffe ffd ... 0cb 0ca 0c9 0c8 dec hex 1111 1111 1111 1111 1111 1110 1111 1111 1101 ... 0000 1100 1011 0000 1100 1010 0000 1100 1001 0000 1100 1000 binary 0000 1111 1111 1111 0000 1111 1111 1110 0000 1111 1111 1101 ... 0000 0000 1100 1011 0000 0000 1100 1010 0000 0000 1100 1001 0000 0000 1100 1000 16-bit result register v vref vinn ? = 2 gnd v vref ? vinp ... 0 0 0000 0000 0000 0000 0000 0000 0000
231 8210b?avr?04/10 xmega d 20.6 compare function the adc has a built in 12-bit compare function. the adc compare register can hold a 12-bit value that represent an analog threshold voltage. the adc can be configured to automatically compare its result with this 12-b it compare value to give an interrupt or event only when the result is above or below the threshold. 20.7 starting a conversion before a conversion is started, the desired input source must be selected for the adc. an adc conversion can either be started by the application software writing to the start conversion bit, or from any of the events in the event system. 20.8 adc clock and conversion timing the adc is clocked from the peripheral clock . the adc can prescale the peripheral clock to provide an adc clock (clk adc ) that is within the minimum and maximum frequency for the adc. figure 20-12. adc prescaler the maximum adc sample rate is gi ven by the adc clock frequency (f adc ). the adc can sam- ple a new measurement once the previous conversion is done. the propagation delay of an adc measurement is given by: res is the resolution, 8- or 12-bit. the propagation delay will increase by one, two or three extra adc clock cycles if the gain stage (gain) is used, according to the following gain settings: ? gain = 1 for 2x and 4x gain settings ? gain = 2 for 8x and 16x gain settings ? gain = 3 for 32x and 64x gain settings 20.8.1 single conversion without gain figure 20-13 on page 232 shows the adc timing for a single conversion without gain. the writ- ing of the start conversion bit, or the event triggering the conversion (start), must occur minimum one peripheral clock cycles before the adc clock cycle where the conversion actually start (indicated with the grey slope of the start trigger). 9-bit adc prescaler clk adc prescaler[2:0] clk/4 clk/8 clk/16 clk/32 clk/64 clk/128 clk per clk/256 clk/512 propagation delay = 1 res 2 ---------- - gain ++ f adc ------------------------------------------
232 8210b?avr?04/10 xmega d the analog input source is sample d in the first half of the first cycle, and the sample time is one- half adc clock period. using a fa ster or slower adc clock and sa mple rate will affect the sample time. the most significant bit (msb) of the result is converted first, and the rest of the bits are con- verted during the next 3 (for 8-bit results) or 5 (for 12-bit results) adc clock cycles. converting one bit takes a half adc clock period. during the last cycle the result is prepared before the interrupt flag is set. the result is available in the result register for readout. figure 20-13. adc timing for one single conversion without gain 20.8.2 single conversion with gain figure 20-14 on page 232 to figure 20-16 on page 233 show the adc timing for one single con- version with various gain settings. as seen in the ?overview? on page 224 the gain stage is placed prior to the actual adc. this means that the gainstage will sample and ampl ify the ana- log input source before the adc samples an converts the amplified analog value. the gain stage will require between one and three adc clock cycles in order to amplify the input source. this will add one to three adc clock cy cles to the total propagation delay compared to single conversion without gain. the sample time for the gain stage is a half adc clock cycle. figure 20-14. adc timing for one single conversion with 2x or 4x gain clk adc start adc sample if converting bit 10 9 8 7 6 5 4 3 2 1 lsb 12345678 msb adc sample converting bit start if gainstage sample gainstage amplify msb 10 9 8 7 6 5 4 3 2 1 lsb clk adc 12345678 9
233 8210b?avr?04/10 xmega d figure 20-15. adc timing for one single conversion with 8x or 16x gain figure 20-16. adc timing for one single conversion with 32x or 64x gain 20.9 adc input model an analog voltage input must be able to fully charge the sample and hold (s/h) capacitor in the adc in order to achieve maximum accuracy. seen externally the adc input consists of a input channel (r channel ) and the switch (r switch ) resistance, and the s/h capacitor. figure 20-17 on page 233 and figure 20-18 on page 234 shows the input models for the adc inputs. figure 20-17. adc input for single ended measurements adc sample converting bit start if gainstage sample gainstage amplify msb 10 9 8 7 6 5 4 3 2 1 lsb clk adc 12345678 9 10 adc sample converting bit start if gainstage sample gainstage amplify msb 10 9 8 7 6 5 4 3 2 1 lsb clk adc 12345678 9 10 11 r channel r switch c sample vcc/2 positive input
234 8210b?avr?04/10 xmega d figure 20-18. adc input for differential measurements and differential measurements with gain in order to achieve n bit accuracy, the source output resistance, r source , must be less than the adc input resistance on a pin: where t s is the adc sample time. for details on r channel , r switch and c sample refer to the adc and adc gain stage electrical charac- teristic in the device datasheet. 20.10 interrupts and events the adc can generate both interrupt requests and events. interrupt requests and events can be generated either when an adc conversion is complete or if an adc measurement is above or below the adc compare register values. 20.11 calibration the adc has a built-in calibration mechanism that calibrates the internal pipeline in the adc. the calibration value from the production test must be loaded from the signature row and into the adc calibration register from softwa re to obtain best possible accuracy. 20.12 register description - adc 20.12.1 ctrla - adc control register a ? bits 7:3 ? reserved these bits are unused a nd reserved for future use. for com patibility reasons always write these bits to zero when this register is written ? bits 2 ? ch0start: adc start single conversion r channel r switch c sample vcc/2 positive input r channel r switch c sample negative input r source t s c sample 2 n 1 + () ln ? ----------------------------------------------- r channel ? r switch ? bit 76543210 +0x00 ? ? ? ? ? ch0start flush enable ctrla read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
235 8210b?avr?04/10 xmega d setting this bit will start an adc conversion. bit is cleared by hardware w hen the conversion has started. writing this bit is equi valent to writing the start bits inside the adc channel register. ? bit 1 ? flush: adc flush: writing this bit to one will flush the adc. when this is done the adc clock will be restarted on the next peripheral clock edge and any ongoing conversion in progress is aborted and lost. after the flush and the adc clock restart, any new conversions pending will start. ? bit 0 ? enable: adc enable setting this bit enables the adc. 20.12.2 ctrlb - adc control register b ? bits 7:5 - reserved these bits are unused and reserv ed for future use. for compatibility reason s, always write these bits to zero when this register is written. ? bit 4 - convmode: adc conversion mode this bit controls whether the adc should work in signed or unsigned mode. by default this bit is zero and the adc is then configured for unsigned mode where single ended and internal signals can be measured. when this bit is set to one the adc is configured for signed mode where also differential input can be used. ? bit 3 - freerun: adc free running mode this bit controls the free running mode for the adc. once a conversion is finished, the next input will be sampled and converted. ? bits 2:1 - resolution[1:0]: adc conversion result resolution these bits define whether the adc completes the conversion at 12- or 8-bit result. they also define whether the 12-bit result is left or right oriented in the 16-bit result registers. see table 20-1 on page 235 for possible settings. ? bit 0 - reserved this bit is unused and reserved for future use. fo r compatibility reasons, a lways write this bit to zero when this register is written. bit 765 4 3 2 1 0 +0x01 ? ? ? convmode freerun resolution[1:0] ?ctrlb read/write r r r r/w r/w r/w r/w r initial value 0 0 0 0 0 0 0 0 table 20-1. adc conversion result resolution resolution[1:0] group co nfiguration description 00 12bit 12-bit result, right adjusted 01 reserved 10 8bit 8-bit result, right adjusted 11 left12bit 12-bit result, left adjusted
236 8210b?avr?04/10 xmega d 20.12.3 refctrl - adc reference control register ? bit 7 ? reserved this bit is unused and reserved for future use. fo r compatibility reasons, a lways write this bit to zero when this register is written. ? bits 6:4 ? refsel[2:0]: adc reference selection these bits selects the reference and conversion range for the adc according to table 20-2 on page 236 . notes: 1. only available if aref exist on port a. 2. only available it aref exist on port b. ? bit 3:2 ? reserved these bits are unused and reserv ed for future use. for compatibility reason s, always write these bits to zero when this register is written. ? bit 1 ? bandgap: bandgap enable setting this bit enables the bandgap to prepare for adc measurement. note that if any other functions are using the bandgap already, this bit do es not need to be set. this could be when the internal 1.00v reference is used in adc or if the brown-out detector is enabled. ? bit 0 ? tempref: temperature reference enable setting this bit enables the temperature reference to prepare for adc measurement. 20.12.4 evctrl - adc event control register bit 765432 1 0 +0x02 ? refsel[2:0] ? ? bandgap tempref refctrl read/write r r/w r/w r/w r r r/w r/w initial value 0 0 0 0 0 0 0 0 table 20-2. adc reference configuration refsel[2:0] group configuration description 000 int1v internal 1.00v 001 intvcc internal v cc /1.6 010 (1) arefa external reference from aref pin on port a. 011 (2) arefb external reference fr om aref pin on port b. 100 101 110 111 bit 76543210 +0x03 ? ? evsel[2:0] ? ? evact0 evctrl read/write r r r/w r/w r/w r r r/w initial value00000000
237 8210b?avr?04/10 xmega d ? bits 7:6 - reserved these bits are unused and reserv ed for future use. for compatibility reason s, always write these bits to zero when this register is written. ? bits 5:3 - evsel[2:0]: ev ent channel input select these bits define which event channel should trigger the adc. see table 20-3 on page 237 . ? bits 2:1 - reserved these bits are unused and reserv ed for future use. for compatibility reason s, always write these bits to zero when this register is written. ? bits 0 - evact0: adc event mode setting this bit to one will enable the event line def ined by evsel to trigger the conversion. writ- ing this bit to zero disable adc event triggering. 20.12.5 prescaler - adc clock prescaler register ? bits 7:3 - reserved these bits are reserved and will always read as zero. for compatibility reasons always write these bits to zero when this register is written. ? bits 2:0 - prescaler[2:0]: adc prescaler configuration these bits define the adc clock relative to the peripheral clock, according to table 20-4 on page 237 . table 20-3. adc event line select evsel[2:0] group configurat ion selected event lines 000 0 event channel 0 selected inputs 001 1 event channel 1 as selected input 010 2 event channel 2 as selected input 011 3 event channel 3 as selected input 111 reserved bit 76543 2 1 0 +0x04 ? ? ? ? ? prescaler[2:0] prescaler read/write r r r r r r/w r/w r/w initial value 0 0 0 0 0 0 0 0 table 20-4. adc prescaler settings prescaler[2:0] group configuration system clock division factor 000 div4 4 001 div8 8 010 div16 16 011 div32 32 100 div64 64
238 8210b?avr?04/10 xmega d 20.12.6 intflags - adc interrupt flag register ? bits 7:1 - reserved these bits are reserved and will always read as zero. for compatibility reasons always write these bits to zero when this register is written. ? bits 0 - ch0if: interrupt flags this flag is set when the adc conversion is complete. if the adc is configured for compare mode, the interrupt flag will be set if the compare condition is met. ch0if is automatically cleared when the adc interrupt vector is executed. the flag can also be cleared by writing a one to its bit location. 20.12.7 temp - adc temporary register ? bits 7:0 - temp[7:0]: adc temporary register this register is used when reading 16-bit registers in the adc controller. the high byte of the 16- bit register is stored here when the low byte read by the cpu. this register can also be read and written from the user software. for more details on 16-bit register access refer to ?accessing 16-bits registers? on page 12 . 20.12.8 call - adc calibration value registers the call and calh register pair hold the 12-bit value adc calibration value cal. the adc is calibrated during production programming, the calibration value must be read from the signature row and written to the cal register from in order to get best possible accuracy. ? bits 7:0 - cal[7:0]: adc calibration value this is the 8 lsb of the 12-bit cal value. 101 div128 128 110 div256 256 111 div512 512 table 20-4. adc prescaler settings bit 76543210 +0x06 ? ? ? ? ? ? ? ch0if intflags read/writerrrrrrrr/w initial value00000000 bit 76543210 +0x07 temp[7:0] temp read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000 bit 76543210 +0x0c cal[7:0] cal read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0
239 8210b?avr?04/10 xmega d 20.12.9 calh - adc calibration value registers ? bits 7:4 - reserved these bits are reserved and will always read as zero. for compatibility reasons always write these bits to zero when this register is written. ? bits 3:0 - cal[11:8]: adc calibration value this is the 4 msb of the 12-bit cal value. 20.12.10 ch0resh - adc channel result register high the ch0resl and ch0resh register pair represents the 16-bit value ch0res. for details on reading 16-bit register refer to ?accessing 16-bits registers? on page 12 . 20.12.10.1 12-bit mode, left adjusted ? bits 7:0 - chres[11:4]: adc channel result, high byte these are the 8 msb of the 12-bit adc result. 20.12.10.2 12-bit mode, right adjusted ? bits 7:4 - reserved these bits will in practice be the extension of the sign bit chres11 when adc works in differen- tial mode and set to zero when adc works in signed mode. ? bits 3:0 - chres[11:8]: adc channel result, high byte these are the 4 msb of the 12-bit adc result. 20.12.10.3 8-bit mode ? bits 7:0 - reserved these bits will in practice be the extension of the sign bit chres7 when adc works in signed mode and set to zero when adc works in single-ended mode. bit 76543210 +0x0d ? ? ? ? cal[11:8] cal read/write r r r r r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 12-bit, left chres[11:4] 12-bit, right ? ? ? ? chres[11:8] 8-bit ? ? ? ? ? ? ? ? read/writerrrrrrrr initial value00000000
240 8210b?avr?04/10 xmega d 20.12.11 ch0resl - adc channel result register low 20.12.11.1 12-/8-bit mode ? bits 7:0 - chres[7:0]: adc channel result, low byte these are the 8 lsb of the adc result. 20.12.11.2 12-bit mode, left adjusted ? bits 7:4 - chres[3:0]: adc channel result, low byte these are the 4 lsb of the 12 bit adc result. ? bits 3:0 - reserved these bits are reserved and will always read as zero. for compatibility reasons always write these bits to zero when this register is written. 20.12.12 cmph - adc compare register high the cmph and cmpl register pair represents the 16-bit value adc compare (cmp). for details on reading and writing 16-bit registers refer to ?accessing 16-bits registers? on page 12 . ? bits 7:0 - cmp[15:0]: adc compare value high byte these are the 8 msb of the 16-bit adc compare value. in signed mode, the number representa- tion is 2's complement and the msb is the sign bit. 20.12.13 cmpl - adc compare register low ? bits 7:0 - cmp[7:0]: adc compare value high byte these are the 8 lsb of the 16-bit adc compare value. in signed mode, the number representa- tion is 2's complement. bit 76543210 12-/8- chres[7:0] 12-bit, left chres[3:0] ? ? ? ? read/writerrrrrrrr initial value00000000 bit 76543210 +0x19 cmp[15:0] cmph read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x18 cmp[7:0] cmpl read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000
241 8210b?avr?04/10 xmega d 20.13 register descr iption - adc channel 20.13.1 ctrl - adc channel control register ? bit 7 - start: start conversion on channel writing this to one will start a c onversion on the channe l. the bit is cleared by hardware when the conversion has started. writin g this bit to one when it alread y is set will have no effect. writ- ing or reading these bits is equivalent to writing the ch0start bit in ?ctrla - adc control register a? on page 234 . ? bits 6:5 - reserved these bits are unused a nd reserved for future use. for com patibility reasons always write these bits to zero when this register is written. ? bits 4:2 - gain[2:0]: adc gain factor these bits define the gain factor in order to amplify input signals before the adc conversion. see table 20-5 on page 241 for different gain factor settings. gain is only valid with certain mux settings, see ?muxctrl - adc channel mux control registers? on page 242 . ? bit 1:0 - inputmode[1:0]: adc input mode these bits define the adc channel input mode. this setting is independent of the adc conv- mode (signed/unsigned mode) setting, but diffe rential input mode can only be done in adc signed mode. in single e nded input mode, th e negative input to the ad c will be connected to a fixed value both for adc signed and unsigned mode. bit 76543210 +0x00 start ? ? gain[2:0} inputmode[1:0] ctrl read/write r/w r r r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 table 20-5. adc gain factor gain[2:0] group configuration gain factor 000 1x 1x 001 2x 2x 010 4x 4x 011 8x 8x 100 16x 16x 101 32x 32x 110 64x 64x 111 div2 1/2x
242 8210b?avr?04/10 xmega d 20.13.2 muxctrl - adc channel mux control registers the mux register defines the input source for the channel. ? bit 7 - reserved this bit is unused and reserved for future use. for compatibility reasons always write this bit to zero when this register is written. ? bits 6:3 - muxpos[3:0]: mux selection on positive adc input these bits define the mux selection for the positive adc input. table 20-8 on page 242 and table 20-9 on page 243 shows the possible input selection for the different input modes. table 20-6. input modes, convmode=0 (unsigned mode) inputmode[1:0] group configuration description 00 internal internal positive input signal 01 singleended single-ended positive input signal 10 reserved 11 reserved table 20-7. input modes, convmode=1 (signed mode) inputmode[1:0] group co nfiguration description 00 internal internal positive input signal 01 singleended single-ended positive input signal 10 diff differential input signal 11 diffwgain differential input signal with gain bit 7 6543210 +0x01 ? muxpos[3:0] ?muxneg[1:0]muxctrl read/write r r/w r/w r/w r/w r r/w r/w initial value 0 0 0 0 0 0 0 0 table 20-8. adc muxpos configuration when inputmode[1:0] = 00 (internal) is used muxpos[2:0] group configuration analog input 000 temp temperature reference. 001 bandgap bandgap voltage 010 scaledvcc 1/10 scaled v cc 011 reserved 100 reserved 101 reserved 110 reserved 111 reserved
243 8210b?avr?04/10 xmega d ? bits 2 - reserved this bit is unused and reserved for future use. for compatibility reasons always write this bit to zero when this register is written. ? bits 1:0 - muxneg[1:0]: mux selection on negative adc input these bits define the mux selection for the nega tive adc input when differential measurements are done. for internal or single-ended measurements, these bits are not in use. table 20-10 on page 243 and table 20-11 on page 244 shows the possible input sections. table 20-9. adc muxpos configuration when inputmode[1:0] = 01 (single-ended), inputmode[1:0] = 10 (differential) or inputpmode[1:0] = 1 (differential with gain) is used. muxpos[3:0] group configuration analog input 0000 pin0 adc0 pin 0001 pin1 adc1 pin 0010 pin2 adc2 pin 0011 pin3 adc3 pin 0100 pin4 adc4 pin 0101 pin5 adc5 pin 0110 pin6 adc6 pin 0111 pin7 adc7 pin 1000 pin8 adc8 pin 1001 pin9 adc9 pin 1010 pin10 adc10 pin 1011 pin11 adc11 pin 1100 pin12 adc12 pin 1101 pin13 adc13 pin 1110 pin14 adc14 pin 1111 pin15 adc15 pin table 20-10. adc muxneg configuration, inputmode[ 1:0] = 10, differential without gain muxnex[1:0] group configuration analog input 00 pin0 adc0 pin 01 pin1 adc1 pin 10 pin2 adc2 pin 11 pin3 adc3 pin
244 8210b?avr?04/10 xmega d 20.13.3 intctrl - adc channel interrupt control registers ? bits 7:4 ? reserved these bits are unused a nd reserved for future use. for com patibility reasons always write these bits to zero when this register is written. ? bit 3:2 ? intmode[1:]: adc interrupt mode these bits select the interrupt mode for channel n according to table 20-12 ? bits 1:0 ? intlvl[1:0]: adc interrupt priority level and enable these bits enable the adc channel interrupt and select the interrupt level as described in ?inter- rupts and programmable multi-level interrupt controller? on page 95 . the enabled interrupt will be triggered when the if in the intflags register is set. 20.13.4 intflags - adc channel interrupt flag registers ? bits 7:1 ? reserved these bits are reserved and will always read as zero. for compatibility reasons always write these bits to zero when this register is written. table 20-11. adc muxneg configuration, inputmod e[1:0] = 11, differential with gain muxneg[1:0] group configuration analog input 00 pin4 adc4 pin 01 pin5 adc5 pin 10 pin6 adc6 pin 11 pin7 adc7 pin bit 76543210 +0x02 ? ? ? ? intmode[1:0] intlvl[1:0] intctrl read/write r r r r r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 table 20-12. adc interrupt mode intmode[1:0] group configuration interrupt mode 00 complete conversion complete 01 below compare result below threshold 10 reserved 11 above compare result above threshold bit 76543210 +0x03 ? ? ? ? ? ? ? if intflags read/writerrrrrrrr/w initial value 0 0 0 0 0 0 0 0
245 8210b?avr?04/10 xmega d ? bit 0 ? if: adc channel interrupt flag the interrupt flag is set when the adc conversion is complete. if the cha nnel is configured for compare mode, the flag will be set if the compar e condition is met. if is automatically cleared when the adc channel interrupt vector is executed. the bit can also be cleared by writing a one to the bit location. 20.13.5 resh - adc channel result register high for all result registers and with any adc result resolution, a signed number is represented in 2?s complement form and the msb represents the sign bit. the resl and resh register pair represents the 16-bit value adcresult. reading and writ- ing 16-bit values require special attention, refer to ?accessing 16-bits registers? on page 12 for details. 20.13.5.1 12-bit mode, left adjusted ? bits 7:0 - res[11:4]: adc channel result, high byte these are the 8 msb of the 12-bit adc result. 20.13.5.2 12-bit mode, right adjusted ? bits 7:4 - reserved these bits will in practice be the extension of the sign bit chres11 when adc works in differen- tial mode and set to zero when adc works in signed mode. ? bits 3:0 - res[11:8]: adc channel result, high byte these are the 4 msb of the 12-bit adc result. 20.13.5.3 8-bit mode ? bits 7:0 - reserved these bits will in practice be the extension of the sign bit chres7 when adc works in signed mode and set to zero when adc works in single-ended mode. 20.13.6 resl - adc channel result register low bit 76543210 12-bit, left. +0x05 res[11:4] 12-bit, right ? ? ? ? res[11:8] 8-bit ? ? ? ? ? ? ? ? read/writerrrrrrrr initial value00000000 bit 76543210 12-/8- +0x04 res[7:0] 12-bit, left. res[3:0] ? ? ? ? read/writerrrrrrrr initial value00000000
246 8210b?avr?04/10 xmega d 20.13.6.1 12-/8-bit mode ? bits 7:0 - res[7:0]: adc channel result, low byte these are the 8 lsb of the adc result. 20.13.6.2 12-bit mode, left adjusted ? bits 7:4 - res[3:0]: adc channel result, low byte these are the 4 lsb of the 12 bit adc result. ? bits 3:0 - reserved these bits are reserved and will always read as zero. for compatibility with future devices, always write these bits to zero when this register is written.
247 8210b?avr?04/10 xmega d 20.14 register summary - adc this is the register summary when the adc is configured to give standard 12-bit results. the register summary for 8-bit and 12-bit left adjusted will be similar, but with some changes in t he result registers ch0resh and ch0resl. address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 ctrla ? ? ? ? ? ch0start flush enable 234 +0x01 ctrlb ? ? ? convmode freerun resolution[1:0] - 235 +0x02 refctrl ? refsel[2:0] - - bandgap tempref 236 +0x03 evctrl ? ? evsel[2:0] - - evact 236 +0x04 prescaler ? ? ? ? ? prescaler[2:0] 237 +0x05 reserved ? ? ? ? ? ? ? ? +0x06 intflags ? ? ? ? ? ? ? ch0if 238 +0x07 temp temp[7:0] 238 +0x08 reserved ? ? ? ? ? ? ? ? +0x09 reserved ? ? ? ? ? ? ? ? +0x0a reserved ? ? ? ? ? ? ? ? +0x0b reserved ? ? ? ? ? ? ? ? +0x0c call cal[7:0] 238 +0x0d calh ? ? ? ?cal[11:8] +0x0e reserved ? ? ? ? ? ? ? ? +0x0f reserved ? ? ? ? ? ? ? ? +0x10 ch0resl ch0res[7:0] 240 +0x11 ch0resh ch0res[15:8] 240 +0x12 reserved ? ? ? ? ? ? ? ? +0x13 reserved ? ? ? ? ? ? ? ? +0x14 reserved ? ? ? ? ? ? ? ? +0x15 reserved ? ? ? ? ? ? ? ? +0x16 reserved ? ? ? ? ? ? ? ? +0x17 reserved ? ? ? ? ? ? ? ? +0x18 cmpl cmp[7:0] 240 +0x19 cmph cmp[15:8] 240 +0x1a reserved ? ? ? ? ? ? ? ? +0x1b reserved ? ? ? ? ? ? ? ? +0x1c reserved ? ? ? ? ? ? ? ? +0x1d reserved ? ? ? ? ? ? ? ? +0x1e reserved ? ? ? ? ? ? ? ? +0x1f reserved ? ? ? ? ? ? ? ? +0x20 ch0 offset ? ? ? ? ? ? ? ? +0x21 reserved ? ? ? ? ? ? ? ? +0x22 reserved ? ? ? ? ? ? ? ? +0x23 reserved ? ? ? ? ? ? ? ?
248 8210b?avr?04/10 xmega d 20.15 register summ ary - adc channel 20.16 interrupt vector summary address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 ctrl start ? ? gain[2:0] inputmode[1:0] 241 +0x01 muxctrl ? muxpos[3:0] - muxneg[1:0] 242 +0x02 intctrl ? ? ? ? intmode[1:0] intlvl[1:0] 244 +0x03 intflags ? ? ? ? ? ? ?if244 +0x04 resl res[7:0] 245 +0x05 resh res[15:8] 245 +0x06 reserved ? ? ? ? ? ? ? ? +0x07 reserved ? ? ? ? ? ? ? ? table 20-13. analog to digital converter interrupt vector and word offset address offset source interr upt description 0x00 ch0 analog to digital converter channel 0 interrupt vector
249 8210b?avr?04/10 xmega d 21. ac - analog comparator 21.1 features ? flexible input selection ? high speed option ? low power option ? selectable input hysteresis ? analog comparator output available on pin ? window mode 21.2 overview the analog comparator (ac) compares the voltage level on two inputs and gives a digital output based on this comparison. the analog comparator may be configured to give interrupt requests and/or events upon several different combinations of input change. two important properties of the analog comparator when it comes to the dynamic behavior, are hysteresis and propagation delay. both these parameters may be adjusted in order to find the optimal operation for each application. the analog comparators are always grouped in pairs (ac0 and ac1) on each analog port. they have identical behavior but separate control registers.
250 8210b?avr?04/10 xmega d figure 21-1. analog comparator overview. ac0 + - pin inputs internal inputs pin inputs internal inputs vcc scaled interrupt sensitivity control interrupts ac1 + - pin inputs internal inputs pin inputs internal inputs vcc scaled events pin 0 output
251 8210b?avr?04/10 xmega d 21.3 input channels each analog comparator has one positive and one negative input. each input may be chosen among a wide selection of input channels: the analog input pins, internal inputs and a scaled inputs. the digital output from the analog comparator is one when the difference between the positive and the negative input is positive, and zero when the difference is negative. 21.3.1 pin inputs the analog input pins on the port can be selected as input to the analog comparator. 21.3.2 internal inputs there are three internal inputs that are directly available for the analog comparator: ? bandgap reference voltage. ? voltage scaler that can do a 64-level scaling of the internal vcc voltage. 21.4 start of signal compare in order to start a signal compare, the analog comparator must be configured with the preferred properties and inputs, before the module is enabled to start comparing the two selected inputs. the result of the comparison is continuous and available for application software and the event system. when the ac is enabled the muxes need some time to connect to the inputs configured. this can result in unexpected transitions on the ac ou tput during this time. in addition if the voltage scaler is used as a input on any of the two ac inside a ac system it has a startuptime that is lagrer than the mux enable time(see ac mdac spesification). this startup time applies even if one ac already uses the voltage scaler as input. 21.5 generating inte rrupts and events the analog comparator can be configured to generate interrupts when the output toggles, when output changes from zero to one (rising edge) or when the output changes from one to zero (fall- ing edge). events will be generated for th e same condition as the in terrupt, and at all times, regardless of the interrupt being enabled or not. 21.6 window mode two analog comparators on the same analog port can be configured to work together in win- dow mode. in this mode a voltage range may be defined, and the analog comparators may give information about whether an input signal is within this range or not.
252 8210b?avr?04/10 xmega d figure 21-2. analog comparator window mode 21.7 input hysteresis application software can select between no, low, and high hysteresis. adding hysteresis can avoid constant toggling of the output if the i nput signals are very close to each other and some noise exists in either of the signals or in the system. 21.8 power consumption vs. propagation delay it is possible to enable high-speed mode to get the shortest possible propagation delay. this mode consumes more power than the default low-power mode that has a longer propagation delay. 21.9 register description 21.9.1 acnctrl ? analog comparator n control register ? bits 7:6 - intmode[1:0]:analog comparator interrupt modes these bits configure the interrupt mode for analog comparator n according to table 21-1 . ac0 + - ac1 + - input signal upper limit of window lower limit of window interrupt sensitivity control interrupts events bit 7654 3210 +0x00 / +0x01 intmode[1:0] intlvl[1:0] hsmode hysmode[2:0] enable acnctrl read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 table 21-1. analog comparator n interrupt settings intmode[1:0] group configuration description 00 bothedges comparator interrupt on output toggle 01 - reserved 10 falling comparator interrupt or event on falling output edge 11 rising comparator interrupt or event on rising output edge
253 8210b?avr?04/10 xmega d ? bits 5:4 - intlvl[1:0]: analog comparator interrupt level these bits enable the analog comparator n interrupt and select the interrupt level as described in ?interrupts and programmable multi-level interrupt controller? on page 95 . the enabled inter- rupt will trigger accordin g to the intmode setting. ? bit 3 - hsmode: analog comparator high-speed mode select setting this bit selects high-speed mode and clearing this bit to select low-power mode. ? bits 2:1 - hysmode[1:0]: analog comparator hysteresis mode select these bits select hysteresis according to table 21-2 . for details on actual hysteresis levels refer to device datasheet. ? bit 0 - enable: analog comparator enable settings this bit enables the analog comparator n. 21.9.2 acnmuxctrl ? analog comparator control register ? bits 7:6 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bits 5:3 - muxpos[2:0]: analog comparator positive input mux selection these bits select which input to be connected to the positive input of analog comparator n, according to table 21-3 . table 21-2. analog comparator n hysteresis settings hysmode[1:0] group configuration description 00 no no hysteresis 01 small small hysteresis 10 large large hysteresis 11 - reserved bit 7 6 543210 +0x02 / +0x03 ? ? muxpos[2:0] muxneg[2:0] acnmuxctrl read/write r r r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 table 21-3. analog comparator n positive input mux selection muxpos[2:0] group configuration description 000 pin0 pin 0 001 pin1 pin 1 010 pin2 pin 2 011 pin3 pin 3 100 pin4 pin 4
254 8210b?avr?04/10 xmega d ? bits 2:0 - muxneg[2:0]: analog comparator negative input mux selection these bits select which input to be connect ed to the negative input of analog comparator n, according to table 21-4 on page 254 . 21.9.3 ctrla ? cont rol register a ? bits 7:1 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 0 ? ac0out: analog comparator output setting this bit makes the output of analog comparator 0 available on pin 7 on the same port. 21.9.4 ctrlb ? cont rol register b ? bits 7:6 - res - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. 101 pin5 pin 5 110 pin6 pin 6 111 - reserved table 21-4. analog comparator n negative input mux selection muxneg[2:0] group configuratio n negative input mux selection 000 pin0 pin 0 001 pin1 pin 1 010 pin3 pin 3 011 pin5 pin 5 100 pin7 pin 7 101 - reserved 110 bandgap internal bandgap voltage 111 scaler vcc voltage scaler table 21-3. analog comparator n positive input mux selection (continued) bit 76543210 +0x04 ? ? ? ? ? ? ? ac0out ctrla read/writerrrrrrrr/w initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x05 ? ? scalefac[5:0] ctrlb read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value00000000
255 8210b?avr?04/10 xmega d ? bits 5:0 - scalefac[5:0]: analog comparator input voltage scaling factor these bits define the scali ng factor for the vcc voltage f . the input to the analog comparator, v scale , is: 21.9.5 winctrl ? analog comparator window function control register ? bits 7:5 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 4 - wen: analog comparator window enable setting this bit enables window mode for the two analog comparators on the same port. ? bits 3:2 - wintmode[1:0]: analog comparator window interrupt mode settings these bits configure the interrupt mode for analog comparator window mode according to table 21-5 . ? bits 1:0 - wintlvl[1:0]: analog comparator window interrupt enable these bits enable the analog comparator window mode interrupt and select the interrupt level as described in ?interrupts and programmable multi-level interrupt controller? on page 95 . the enabled interrupt will trigger acco rding to the wintmode setting. 21.9.6 status ? analog comparator common status register ? bits 7:6 - wstate[1:0]: analog comparator window mode current state these bits show the current state of the signal if the window mode is enabled according to table 21-6 . v scale v cc scalefac 1 + () ? 64 ------------------------------------------------------------ - = bit 76543210 +0x06 ? ? ? wen wintmode[1:0] wintlvl[1:0] winctrl read/write r r r r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 table 21-5. analog comparator window mode interrupt settings wintmode[1:0] group configuration description 00 above interrupt on signal above window 01 inside interrupt on signal inside window 10 below interrupt on signal below window 11 outside interrupt on signal outside window bit 76543210 +0x07 wstate[1:0] ac1state ac0state ? wif ac1if ac0if status read/write r/w r/w r/w r/w r r/w r/w r/w initial value 0 0 0 0 0 0 0 0
256 8210b?avr?04/10 xmega d ? bit 5 - ac1state: analog comparator 1 current state this bit shows the current state of the input signal to analog comparator 1. ? bit 4 - ac0state: analog comparator 0 current state this bit shows the current state of the input signal to analog comparator 0. ? bit 3 - reserved this bit is unused and reserved fo r future use. for comp atibility with future devices, always write this bit to zero when this register is written. ? bit 2 - wif: analog comparator window interrupt flag this is the interrupt flag for the window mode. wif is set according to the wintmode setting in the ?winctrl ? analog comparator window function control register? on page 255 . the wif is automatically cleared when the analog comparator window interrupt vector is exe- cuted. the flag can also be cleared by writing a one to its bit location. ? bit 1 - ac1if: analog comparator 1 interrupt flag this is the interrupt flag for analog comparator 1. ac1if is set according to the intmode set- ting in the corresponding ?acnctrl ? analog comparator n control register? on page 252 . the ac1if is automatically cleared when the analog comparator 1 interrupt vector is executed. the flag can also be cleared by writing a one to its bit location. ? bit 0 - ac0if: analog comparator 0 interrupt flag this is the interrupt flag for analog comparator 0. ac0if is set according to the intmode set- ting in the corresponding ?acnctrl ? analog comparator n control register? on page 252 . the ac0if is automatically cleared when the analog comparator interrupt vector is executed. the flag can also be cleared by writing a one to its bit location. table 21-6. analog comparator window mode current state wstate[1:0] group configuration description 00 above signal is above window 01 inside signal is inside window 10 below signal is below window 11 - reserved
257 8210b?avr?04/10 xmega d 21.10 register summary 21.11 interrupt vector summary address name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 ac0ctrl intmode[1:0] intlvl[1:0] hsmode hysmode[1:0] enable 252 +0x01 ac1ctrl intmode[1:0] intlvl[1:0] hsmode hysmode[1:0] enable 252 +0x02 ac0muxctr ? ? muxpos[2:0] muxneg[2:0] 253 +0x03 ac1muxctr ? ? muxpos[2:0] muxneg[2:0] 253 +0x04 ctrla ? ? ? ? ? ? ?acoout254 +0x05 ctrlb ? ? scalefac5:0] 254 +0x06 winctrl ? ? ? wen wintmode[1:0] wintlvl[1:0] 255 +0x07 status wstate[1:0] ac1state ac0state ? wif ac1if ac0if 255 table 21-7. analog comparator interrupt vectors offset source interrupt description 0x00 comp0_vect analog comparator 0 interrupt vector 0x02 comp1_vect analog comparator 1 interrupt vector 0x04 window_vect analog comparator window interrupt vector
258 8210b?avr?04/10 xmega d 22. program and debug interface 22.1 features ? program and debug interface (pdi) ? 2-pin interface for external programming and on-chip debugging ? uses reset pin and dedicated test pin ? no i/o pins required during programming or debugging ? programming features ? flexible communication protocol ? 8 flexible instructions. ? minimal protocol overhead. ? fast ? 10 mhz programming clock at 1.8v v cc ? reliable ? built in error detection and handling ? debugging features ? non-intrusive operation ? uses no hardware or software resource ? complete program flow control ? symbolic debugging support in hardware ? go, stop, reset, step into, step over, step out, run-to-cursor ? 1 dedicated program address breakpoint or symbolic breakpoint for avr studio/emulator ? 4 hardware breakpoints ? unlimited number of user program breakpoints ? uses cpu for accessing i/o, data, and program ? high speed operation ? no limitation on system clock frequency 22.2 overview the program and debug interface (pdi) is an atmel proprietary interface for external program- ming and on-chip debugging of the device. the pdi supports high-speed programming of all non-volatile memory (nvm) spaces; flash, eepom, fuses, lockbits and the user signature row. this is done by access ing the nvm con- troller, and executing nvm controller commands as described in memory programming. the on-chip debug (ocd) system supports fully intrusive operation. during debugging no soft- ware or hardware resources in the device is used. the ocd system has full program flow control, supports unlimited number of program and data breakpoints and has full access (read/write) to all memories. both programming and debugging can be done through two physical interfaces. the primary interface is the pdi physical. this is a 2-pin interface using the reset pin for the clock input (pdi_clk), and the dedicated test pin for data input and output (pdi_data). unless otherwise stated, all references to the pdi assumes access through the pdi physical. any external pro- grammer or on-chip debugger/emulator can be directly connected to these interfaces, and no external components are required.
259 8210b?avr?04/10 xmega d figure 22-1. the pdi with pdi physical and closely related modules (grey) 22.3 pdi physical the pdi physical layer handles the basic low-level serial communication. the physical layer uses a bi-directional half-duplex synchronous serial receiver and transmitter (as a usart in usrt mode). the physical layer includes start-of-frame detection, frame error detection, parity generation, parity error detec tion, and collision detection. the pdi is accessed through two pins: ? pdi_clk: pdi clock input (reset pin). ? pdi_data: pdi data input/output (test pin). in addition to these two pins, v cc and gnd must also be connected between the external pro- grammer/debugger and the device. figure 22-2 on page 259 shows a typical connection. figure 22-2. pdi connection the remainder of this section is only intended for third parties developing programming support for xmega. 22.3.1 enabling the pdi physical must be enabled before it can be used. this is done by first forcing the pdi_data line high for a period longer than the equivalent external reset minimum pulse width pdi controller pdi physical (physical layer) ocd nvm controller program and debug interface (pdi) pdi_clk pdi_data nvm memories internal interfaces pdibus programmer/ debugger pdi_data (test) vcc pdi_clk (reset) gnd
260 8210b?avr?04/10 xmega d (refer to device datasheet fo r external reset pulse width da ta). this will disable the reset func- tionality of the reset pin, if not already disabled by the fuse settings. in the next step of the enabling procedure the pdi_data line must be kept high for 16 pdi_clk cycles (16 positive edges detected). the first pdi_clk cycle must start no later than 100us after the reset functionality of the reset pin was disabled. if this does not occur in time the reset functionality of the reset pin is automatically enabled again and the enabling procedure must start over again. after this the pdi is enabled and ready to rece ive instructions. the enable sequence is shown in figure 22-3 on page 260 . from the pdi_data line goes high and until the first pdi_clk start, the the pdi_data pin has en internal pull-down resistor that is enabled when the pdi is enabled. figure 22-3. sequence for enabling the pdi. 22.3.2 disabling if the clock frequency on the pdi_clk is lower than approximately 10 khz, this is regarding as inactivity on the clock line. this will then automatically disable the pdi. if not disabled by fuse, the reset function on the reset (pdi_clk) pin is automatically enabled again. if the time-out occurs during the pdi enabling sequence, the whole sequence must be started from the beginning. this also means that the minimum programming frequency is approximately 10 khz. 22.3.3 frame format and characters the pdi physical layer uses a fixed frame format. a serial frame is defined to be one character of eight data bits with start and stop bits and a parity bit. figure 22-4. pdi serial frame format. disable reset function on reset (pdi_clk) pin activate pdi pdi_data pdi_clk table 1. st start bit, always low. (0-7) data bits (0 to 7) p parity bit, even parity is used sp1 stop bit 1, always high. sp2 stop bit 2, always high. st 012 3 4567p sp1 frame sp2 (idle) (st/idle)
261 8210b?avr?04/10 xmega d 22.3.3.1 characters three different characters, data, break and idle, are used. the break character is equal to 12 bit-length of low level. the idle character is equal to 12 bit-length of high level. both the break and the idle character can be extended beyond the bit-length of 12. figure 22-5. characters and timing for the pdi physical. 22.3.4 serial transmission and reception the pdi physical layer is either in transmit (tx) or receive (rx) mode of operation. by default it is in rx mode, waiting for a start bit. the programmer and the pdi operate synchronously on the pdi_clk provided by the program- mer. the dependency between the clock edges and data sampling or data change is fixed. as illustrated in figure 22-6 on page 261 , output data (either from the programmer or from the pdi) is always set up (changed) on t he falling edge of pdi_clk, while data is always sampled on the rising edge of pdi_clk. figure 22-6. changing and sampling of data. 22.3.5 serial transmission when a data transmission is initiated (by the pdi controller), the transmitter simply shifts the start bit, data bits, the parity bit, and the two stop bits out on the pdi_data line. the transmis- sion speed is dictated by the pdi_clk signal. wh ile in transmission mode, idle bits (high bits) are automatically transmi tted to fill possible gaps between successive data characters. if a col- lision is detected during transmission, the output dr iver is disabled and the interface is put into a rx mode waiting for a break character. start 012 3 4567p stop 1 idle character break idle 1 data character 1 break character pdi_clk pdi_data sample sample sample
262 8210b?avr?04/10 xmega d 22.3.5.1 drive contention and collision detection in order to reduce the effect of a drive contention (the pdi and the programmer drives the pdi_data line at the same time ), a mechanism for collision dete ction is supported. the mecha- nism is based on the way the pdi drives data out on the pdi_data line. as shown in figure 7, the output pin driver is only active when the output value changes (from 0-1 or 1-0). hence, if two or more successive bit values are the same, the value is only actively driven the first clock cycle. after this point the output driver is auto matically tri-stated, and the pdi_data pin has a bus-keeper responsible for keeping the pin-valu e unchanged until the output driver is re-enabled due to a bit value change. figure 22-7. driving data out on the pdi_data using bus-keeper if the programmer and the pdi both drives the pdi_data line at the same time, the situation of drive contention will oc cur as illustrated in figure 22-8 on page 262 . every time a bit value is kept for two or more clock cycles, the pdi is able to verify that the correct bit value is driven on the pdi_data line. if the programmer is drivin g the pdi_data line to the opposite bit value than what the pdi expects, a collision is detected. figure 22-8. drive contention and collision de tection on the pdi_data line as long as the pdi transmits al ternating ones and zeros, collisi ons cannot be detected because the output driver will be active all the time pr eventing polling of the pdi_data line. however, within a single frame the two stop bits shoul d always be transmitted as ones, enabling collision detection at least once per frame. 10110 output enable pdi_clk driven output 0 1 pdi_data pdi_clk pdi output pdi_data 10x1 1 programmer output x1 collision detect = collision
263 8210b?avr?04/10 xmega d 22.3.6 serial reception when a start bit is detected, the receiver starts to collect the eight data bits and shift them into the shift register. if the parity bit does not correspond to the parity of the data bits, a parity error has occurred. if one or both of the stop bits are low, a frame error has occurred. if the parity bit is correct, and no frame error detected, the received data bits are parallelized and made available for the pdi controller. 22.3.6.1 break detector when the pdi is in tx-mode, a break character signalized by the programmer will not be inter- preted as a break, but cause a generic data collis ion. when the pdi is in rx-mode, a break character will be recognized as a break. by transmitting two succes sive break characters (must be separated by one or more high bits), the la st break character will always be recog- nized as a break, regardless of whether the pdi was in tx- or rx-mode initially. 22.3.7 direction change in order to ensure correct timing of the half-duplex operation, a simple guard time mechanism is added to the pdi physical interface during direction change. when the pdi changes from operating in rx-mode to operate in tx-mode, a configurable number of additional idle bits are inserted before the start bit is transmitted. t he minimum transition time between rx- and tx- mode is two idle cycles, and these are always inserted. writing the guard time bits in the pdi controller?s control register specifies the additional guard time. the default guard time value is +128 bits. figure 22-9. pdi direction change by inserting idle bits the programmer will loose control of the pdi_data line at the point where the pdi target changes from rx- to tx-mode. the guard time relaxes this critical phase of the communica- tion. when the programmer changes from rx-mo de to tx-mode, minimum a single idle bit should be inserted before the start bit is transmitted. 22.4 pdi controller the pdi controller includes data transmission/reception on a byte level, command decoding, high-level direction control, control and status register access, exception handling, and clock switching (pdi_clk or tck). the interaction bet ween a programmer and the pdi controller is based on a scheme where the programmer transmits various types of requests to the pdi con- troller, which in tu rn responds in a way according to the specific request. a programmer request comes in the form of an instruction, which may be followed by one or more byte operands. the pdi controller response may be silent (e.g. a data byte is stored to a location within the target), or it may involve data to be returned back to the programmer (e.g. a data byte is read from a location within the target). st p sp1 1 data character sp2 idle bits st v 1 data character sp1 sp2 dir. change d2w data receive (rx) d2w data transmit (tx) data from d2w interface to emulator data from emulator to d2w interface guard time # idle bits inserted
264 8210b?avr?04/10 xmega d 22.4.1 accessing internal interfaces after an external programmer has established communication with the pdi, the internal inter- faces are not accessible by default. to get access to the nvm controller and the nvm memories for programming, a un ique key must be signalized by using the key instruction. the internal interfaces is accessed as one linear address space using a dedicated bus (pdibus) between the pdi and the internal interfaces. 22.4.2 nvm programming key the key that must be sent using the key instruct ion is 64 bits long. the key that will enable nvm programming is: 0x1289ab45cdd888ff 22.4.3 exception handling there are several situations that are consider ed exceptions from normal operation. the excep- tions depends on whether the pdi is in rx - or tx mode. while the pdi is in rx mode, these exceptions are defined as: ?pdi: ? the physical layer detects a parity error. ? the physical layer detects a frame error. ? the physical layer recognizes a break charac ter (also dete cted as a frame error). while the pdi is in tx mode, these exceptions are defined: ?pdi: ? the physical layer det ects a data collision. all exceptions are signalized to the pdi contro ller. all on-going operations are then aborted and the pdi is put in the error state. the pdi will remain in this state un til a break is sent from the external programme r, and this will bring the pdi ba ck to its default rx state. due to this mechanism the programmer can always synchronize the protocol by transmitting two successive break characters. 22.4.4 reset signalling through the reset register, the programmer can issue a reset and force the device into reset. after clearing the reset register, reset is released unless some other reset source is active. 22.4.5 instruction set the pdi has a small instructions set that is used fo r all access to the pdi itself and to the internal interfaces.all instructions are byte instructions. most of the instructions require a number of byte operands following the instruction. the instructions allow to external programmer to access the pdi controller, the nvm cont roller and the nvm memories. 22.4.5.1 lds - load data from pdibus data space using direct addressing the lds instruction is used to load data from the pdibus data space for serial read-out. the lds instruction is based on direct addressing, which means that the address must be given as an argument to the instruction. even though the protocol is based on byte-wise communication, the lds instruction supports multiple-bytes address - and data access. four different address/data sizes are supported; byte, word, 3 bytes, and long (4 bytes). it should be noted that multiple-bytes access is intern ally broken down to repeated single-byte accesses. the main
265 8210b?avr?04/10 xmega d advantage with the multiple-bytes access is that it gives a way to reduce the protocol overhead. when using the lds, the address byte(s) must be transmitted before the data transfer. 22.4.5.2 sts - store data to pdibus data space using direct addressing the st instruction is used to store data that is se rially shifted into the ph ysical layer shift-register to locations within the pdibus data space. the sts instruction is based on direct addressing, which means that the address must be given as an argument to the instruction. even though the protocol is based on byte-wise communication, the st instruction supports multiple-bytes address - and data access. four different address/data sizes are supported; byte, word, 3 bytes, and long (4 bytes). it should be noted that mult iple-bytes access is internally broken down to repeated single-byte accesses. the main advant age with the multiple-bytes access is that it gives a way to reduce the protocol overhead. when using the sts, the address byte(s) must be transmitted before the data transfer. 22.4.5.3 ld - load data from pdibus data space using indirect addressing the ld instruction is used to load data from the pdibus data space to the physical layer shift- register for serial read-out. the ld instruction is based on indirect addres sing (pointer access), which means that the address must be stored into the pointer register prior to the data access. indirect addressing can be combined with pointer increment. in addition to read data from the pdibus data space, the pointer register can be read by the ld instruction. even though the protocol is based on byte-wise communication, the ld instruction supports multiple-bytes address - and data access. four different address/data sizes are supported; byte, word, 3 bytes, and long (4 bytes). it should be noted that mult iple-bytes access is internally broken down to repeated single-byte accesses. the main advant age with the multiple-bytes access is that it gives a way to reduce the protocol overhead. 22.4.5.4 st - store data to pdibus data space using indirect addressing the st instruction is used to store data that is se rially shifted into the ph ysical layer shift-register to locations within the pdibus data space. the st instruction is based on indirect addressing (pointer access), which means that the address must be stored into the pointer register prior to the data access. indirect addressing can be combined with pointer increment. in addition to write data to the pdibus data space, the pointer register can be written by the st instruction. even though the protocol is based on byte-wise communication, the st instruction supports multiple- bytes address - and data access. four different address/data sizes are supported; byte, word, 3 bytes, and long (4 bytes). it should be noted that multiple-bytes access is internally broken down to repeated single-byte accesses. the main advantage with the multiple-bytes access is that it gives a way to reduce the protocol overhead. 22.4.5.5 ldcs - load data from pdi control and status register space the ldcs instruction is used to load data from the pdi control and status registers to the physical layer shift-register for serial read-out. the ldcs instruction supports only direct addressing and single-byte access. 22.4.5.6 stcs - store data to pdi control and status register space the stcs instruction is used to store data that is serially shifted into th e physical layer shift-reg- ister to locations within the pdi control and st atus registers. the stcs instruction supports only direct addressing and single-byte access.
266 8210b?avr?04/10 xmega d 22.4.5.7 key - set activation key the key instruction is used to communicate the activation key bytes that is required for activat- ing the nvm interfaces. 22.4.5.8 repeat - set instruction repeat counter the repeat instruction is used to store count val ues that are serially shifted into the physical layer shift-register to the repeat counter regist er. the instruction that is loaded directly after the repeat instruction operand(s) will be re peated a number of times according to the speci- fied repeat counter register value. hence, the initial repeat counter value plus one, gives the total number of times the instruction will be executed. setting the repeat counter register to zero makes the following instruction run once without being repeated. the repeat cannot be repea ted. the key instruction cannot be repeated, and will override the current value of the repeat counter register 22.4.6 instruction set summary the pdi instruction set summary is shown in figure 22-10 on page 267 .
267 8210b?avr?04/10 xmega d figure 22-10. pdi instruction set summary 22.5 register description - pdi instruction and ad dressing registers these registers are all internal registers that are involved in instruction decoding or pdibus addressing. none of these registers are ac cessible as register in a register space. 22.5.1 instruction register when an instruction is successfully shifted into the physical layer shift-register, it is copied into the instruction register. the instruction is retained until another instruction is loaded. the rea- son for this is that the repeat command may force the same instruction to be run repeatedly requiring command decoding to be performed several times on the same instruction. 22.5.2 pointer register the pointer register is used to store an address value specifying locations within the pdibus address space. during direct data access, the pointer register is updated by the specified num- ber of address bytes given as operand bytes to the instruction. during indirect data access, addressing is based on an address already stored in the pointer register prior to the access 0 0 lds 0 size a size b cmd 0 1 0 sts 1 0 0 ldcs cs address 1 1 0 stcs 1 1 0 0 0 key 1 1 0 0 0 0 repeat 1 size b lds sts st 0 1 0 0 0 1 1 1 ld 0 0 0 0 cmd ldcs (lds control/status) stcs (sts control/status) key 1 0 0 1 1 1 repeat 1 1 1 1 0 0 size b - data size byte 3 bytes long (4 bytes) 0 1 0 0 0 1 1 1 word (2 bytes) cs address (cs - control/status reg.) 0 0 0 register 0 register 2 reserved register 1 0 0 0 0 1 0 1 0 0 0 1 0 1 reserved 1 1 1 1 ...... 0 0 size a - address size (direct access) byte 3 bytes long (4 bytes) 0 1 0 0 0 1 1 1 word (2 bytes) 0 0 ld 1 ptr size a/b cmd 0 1 1 st 0 0 0 0 ptr - pointer access (indirect access) *(ptr) ptr ptr++ - reserved 0 1 0 0 0 1 1 1 *(ptr++) 0 0
268 8210b?avr?04/10 xmega d itself. indirect data access can be optionally combined with pointer register post-increment. the indirect access mode has an option that makes it possible to load or read the pointer register without accessing any other registers. any register update is performed in a little-endian fashion. hence, loading a single byte of the address register will always update the lsb byte while the msb bytes are left unchanged. the pointer register is not involved in addressing registers in the pdi control and status regis- ter space (csrs space). 22.5.3 repeat counter register the repeat instruction will alwa ys be accompanied by one or more operand bytes that define the number of times the next instruction should be repeated. these operand bytes are copied into the repeat counter register upon reception. during the repeated executions of the instruc- tion following immediatel y after the repeat instruction and its operands, t he repeat counter register is decremented until it reaches zero, indi cating that all repetitions are completed. the repeat counter is also involved in key reception. 22.5.4 operand count register immediately after and instruction (except the ldcs and the stcs instructions) a specified num- ber of operands or data bytes (given by the size parts of the instruction) are expected. the operand count register is used to keep track of how many bytes that have been transferred.
269 8210b?avr?04/10 xmega d 22.6 register descrip tion - pdi control and status register these register are registers that are accessible in the pdi control and status register space (csrs) using the instructions ldcs and stcs. the csrs is allocated for registers directly involved in configuration and status monitoring of the pdi itself. 22.6.1 status - program and debug interface status register ? bit 7:2 - reserved these bits are reserved and will always be read as zero. for compatibility with future devices, always write these bits to zero when this register is written. ? bit 1- nvmen: non-volatile memory enable this status bit is set when the key signalling enables the nvm programming interface. the external programmer can poll this bit to verify successful enabling. writing the nvmen bit dis- ables the nvm interface ? bit 0 - reserved this bit is reserved and will a lways be read as zero. for compat ibility with future devices, always write this bit to zero when this register is written. 22.6.2 reset - program and debug interface reset register ? bit 7:0 - reset[7:0]: reset signature when the reset signature - 0x59 - is written to reset, the device is forced into reset. the device is kept in reset until reset is written with a data value different from the reset signature (0x00 is recommended). reading the least lsb bit the will return the status of the reset. the 7 msb bits will always return the va lue 0x00 regardless of whether th e device is in reset or not. 22.6.3 ctrl - program and debug interface control register bit 76543210 +0x00 ? ? ? ? ? ? nvmen ? status read/write rrrrrrrr initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x01 reset[7:0] ctrlb read/write r/w r/w r/w r/w r/w r/w r/w r/w initial value 0 0 0 0 0 0 0 0 bit 76543210 +0x02 ? ? ? ? ? guardtime[2:0] ctrl read/write r r r r r r/w r/w r/w initial value 0 0 0 0 0 0 0 0
270 8210b?avr?04/10 xmega d ? bit 7:3 - reserved these bits are unus ed and reserved for future use. for compatibility with futu re devices, always write these bits to zero when this register is written. ? bit 2:0 - guardtime[2:0]: guard time these bits specify the number of additional idle bi ts of guard time that are inserted in between pdi reception and - transmission direction change. the default guard time is 128 idle bits, and the available settings is shown in table 22-1 on page 270 . in order to speed up the commu- nication, the guard time should be set to the lo west safe configuration accepted. it should be noted that no guard time is inserted when switching from tx - to rx mode. table 22-1. guard time settings guardtime number of idle bits 000 +128 001 +64 010 +32 011 +16 100 +8 101 +4 110 +2 111 +0
271 8210b?avr?04/10 xmega d 22.7 register summary address name address name bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 page +0x00 status ? ? ? ? ? ? nvmen ?269 +0x01 reset reset[7:0] 269 +0x02 ctrl ? ? ? ? ?guardtime[2:0]269 +0x03 reserved ? ? ? ? ? ? ? ? +0x04 reserved ? ? ? ? ? ? ? ? +0x05 reserved ? ? ? ? ? ? ? ? +0x06 reserved ? ? ? ? ? ? ? ? +0x07 reserved ? ? ? ? ? ? ? ? +0x08 reserved ? ? ? ? ? ? ? ? +0x09 reserved ? ? ? ? ? ? ? ? +0x0a reserved ? ? ? ? ? ? ? ? +0x0b reserved ? ? ? ? ? ? ? ? +0x0c reserved ? ? ? ? ? ? ? ? +0x0d reserved ? ? ? ? ? ? ? ? +0x0e reserved ? ? ? ? ? ? ? ? +0x0f reserved ? ? ? ? ? ? ? ? +0x10 reserved ? ? ? ? ? ? ? ?
272 8210b?avr?04/10 xmega d 23. memory programming 23.1 features ? read and write access to all memory spaces from ? external programmers ? application software ? self-programming and boot loader support ? real read-while-write self-programming ? the cpu can run and execute code while flash is being programmed ? any communication interface can be used for program upload/download ? external programming ? support for in-system and production programming ? programming through serial pdi interface ? fast and reliable interfaces. ? high security with separate boot lock bits for ? external programming access ? boot loader section access ? application section access ? application table access ? reset fuse to select reset vector address to the start of the ? application section, or ? boot loader section ? code efficient algorithm ? efficient read-modify-write support 23.2 overview this section describes how to program the non volatile memory (nvm) in xmega, and covers both self-programming and external programmi ng. the nvm consist of the flash program mem- ory, user signature and calibration rows, fuses and lock bits, and eeprom data memory. for details on the actual memories, how they are or ganized and the register description for the nvm controller used to access the memories, refer to ?memories? on page 18 . the nvm can be accessed for read and write both from application software through self-pro- gramming and from an external programmer. for both external programming and self- programming access to the nvm is done through the common nvm controller, and the two methods of programming are very similar. memory access is done by loading address and/or data into the nvm, and a set of commands and triggers that make the nvm controller perform specific tasks on the nvm. from external programming all memory spaces can be read and written, expect for the calibra- tion row which can only be read. the device can be programmed in-system and is accessed through the pdi using the pdi interface, ?external programming? on page 288 describes pdi in detail. self-programming and boot loader support allows application software in the device to read and write the flash, user si gnature row and eeprom, wr ite the lock bits to a more secure setting, and read the calibration row and fuses. the flash allows read-while-write self-programming meaning that the cpu can continue to operate and execute code while the flash is being pro- grammed. ?self-programming and boot loader support? on page 276 describes this in detail.
273 8210b?avr?04/10 xmega d for both self-programming and ex ternal programming it is possi ble to run a crc check on the flash or a section of the flash to verify its content. the device can be locked to prevent read and/or write of the nvm. there are separate lock bits for external programming access, and self-programming access to the boot loader section, application section and application table section. 23.3 nvm controller all access to the non volatile memories is done through the nvm controller. this controls all nvm timing and access privileges, and hold the status of the nvm. this is the common nvm interface for both the external programming and self-programming. for more details on the nvm controller refer to ?register description? on page 294 . 23.4 nvm commands the nvm controller has a set of commands that decide the task to perform on the nvm. this is issued to the nvm controller by writing the selected command to the nvm command register. in addition data and addresses must be read/written from/to the nvm data and address regis- ters for memory read/write operations. when a selected command is loaded and address and data is setup for the operation, each command has a trigger that will start the operation. bases on the triggers, there are three main types of commands. 23.4.1 action triggered commands action triggered commands are triggered when the command execute (cmdex) bit in the nvm control register a (ctrla) is written. action triggered commands typically are used for opera- tions which do not read or write the nvm such as the crc check. 23.4.2 nvm read triggered commands nvm read triggered commands are triggered when the nvm memory is read, and this is typically used for nvm read operations. 23.4.3 nvm write triggered commands nvm write triggered commands are triggered when the nvn is written, and this is typically used for nvm write operations. 23.4.4 ccp write/execute protection most command triggers are protected from acci dental modification/execution during self-pro- gramming. this is done using the configurat ion change protection (ccp) feature which requires a special write or execute sequence in order to change a bit or execute an instruction. for details on the ccp, refer to ?configuration change protection? on page 12 23.5 nvm controller busy when the nvm controller is busy performing an operation, the busy flag in the nvm status register is set and the following registers are blocked for write access: ? nvm command register ? nvm control a register ? nvm control b register ? nvm address registers
274 8210b?avr?04/10 xmega d ? nvm data registers this ensures that the given command is exec uted and the operation finished before a new can start. the external programmer or application software must ensure that the nvm is not addressed while busy with a programming operation. programming any part of th e nvm will automatically block: ? all programming to other parts of the nvm. ? all loading/erasing of the flash and eeprom page buffers. ? all nvm read from external programmers. ? all nvm read from the application section. during self-programming interrupts must be disabled, or the interrupt vector table should be moved to the boot loader sections as described in ?interrupts and programmable multi-level interrupt controller? on page 117 . 23.6 flash and eeprom page buffers the flash memory is upd ated in a page-by- page fashion. the eeprom can be upda ted both in a byte-by-byte and page-by-page fashion. flash and eeprom page programming is done by first filling the associated page buffer, and then writing the entire page buffer to a selected page in flash or eeprom. the size of the page buffers depend on the flash and eeprom si ze in each device, and details on page size and page number is described in each device datasheet. 23.6.1 flash page buffer the flash page buffer is filled one word at a time, and it must be erased before it can be loaded. if an already loaded location is written again, this will co rrupt the content of that flash page buf- fer location. flash page buffer locations that are not loaded will have the value 0xffff, and this value will then be programmed into the flash page locations. the flash page buffer is automatically erased after: ? a system reset. ? executing the write flash page command. ? executing the erase and write flash page command. ? executing the signature row write command. ? executing the write lock bit command. 23.6.2 eeprom page buffer the eeprom page buffer is filled one byte at a ti me and it must be erased before it can be loaded. if an already loaded location is written tw ice, this will corrupt the content of that eeprom page buffer location. eeprom page buffer locations that are loaded will get ta gged by the nvm controller. during a page write or page erase, only ta rget locations will be written or erased. locations that are not target, will not be written or erased, and the corresponding eeprom location will remain unchanged. this means that also before an eeprom page erase, data must be loaded to the selected page buffer location to tag them. if the data in the page buffer is not going to be written afterword, the actual values in the buffer does matter.
275 8210b?avr?04/10 xmega d the eeprom page buffer is automatically erased after: ? a system reset. ? executing the write eeprom page command. ? executing the erase and write eeprom page command. ? executing the write lock bit and write fuse commands 23.7 flash and eeprom programming sequences for flash and eeprom p age programming, filling the page bu ffers and writing the page buffer into flash or eeprom is two separate operations. the sequence of this is the same for both self-programming and external programming. 23.7.1 flash programming sequence before programming a flash page with the data in the flash page buffer, the flash page must be erased. programming an un-e rased flash page will corrupt th e content in the flash page. the flash page buffer can be f illed either before the erase flas h page operatio n or between a erase flash page and a write flash page operation: alternative 1, fill the bu ffer before a split page erase and page write: ? fill the flash page buffer. ? perform a flash page erase. ? perform a flash page write. alternative 2, fill the page buffer before an atom ic page erase and write: ? fill the flash page buffer. ? perform a page erase and write. alternative 3, fill the bu ffer after a page erase: ? perform a flash page erase. ? fill the flash page buffer. ? perform a flash page write. the nvm command set supports both atomic erase and write operations, and split page erase and page write commands. this split commands e nables shorter programming time for each command and the erase operations can be done during non-time-critical programming execu- tion. when using alternative 1 or 2 above for self-programming, the boot loader provides an effective read-modify-write feature, which allows the software to first read the page, do the nec- essary changes, and then write back the modified data. if alternative 3 is used, it is not possible to read the old data while loading, since the page is already erased. the page address must be the same for both page erase and page write operations when using alternative 1 or 3. 23.7.2 eeprom programming sequence before programming an eeprom page with the selected number of data bytes stored in the eeprom page buffer, the selected locations in the eeprom page must be erased. program- ming an un-erased eepr om page will corrupt th e content in the eepr om page. the eeprom page buffer must be loaded before any page erase or page write operations:
276 8210b?avr?04/10 xmega d alternative 1, fill the page buffer be fore a page erase: ? fill the eeprom page buffer with the selected number of bytes. ? perform a eeprom page erase. ? perform a eeprom page write. alternative 2, fill the buffer before a page er ase and write: ? fill the eeprom page buffer with the selected number of bytes. ? perform an eeprom page erase and write. 23.8 protection of nvm to protect the flash and eeprom memories from wr ite and/or read, lock bits can be set to restrict access from external programmers and the application software. refer to ?lockbits - non-volatile memory lock bit register? on page 29 for details on the available lock bit settings and how to use them. 23.9 preventing nvm corruption during periods when the v cc voltage is below the minimum operating voltage for the device, the result from a flash memory read or write can be corrupt as supply voltage is too low for the cpu and the flash to operate properly. 23.9.1 write corruption to ensure that the voltage is correct during a complete write sequence to the flash memory, the bod is automatically enabled by hardware wh en the write sequence starts. if a bod reset occurs, the programming sequence will be aborted immediately. if this happens, the nvm pro- gramming should be restarted when the power is sufficient again in case the write sequence failed or only partly succeeded. 23.9.2 read corruption the nvm can be read incorrectly if the supply vo ltage is too low so the cpu execute instructions incorrectly. to ensure that this does not happen the bod can be enabled. 23.10 self-programming an d boot loader support both the eeprom and the flash memory can be read and written from the application software in the device. this is referred to as self-p rogramming. a boot loader (application code located in the boot loader section of the flash) can both read and write the flash program memory, user signature row and eeprom, an d write the lock bits to a mo re secure setti ng. application code in both the application section can read from the flash, user signature row, calibration row and fuses, and read and write the eeprom. 23.10.1 flash programming the boot loader support provides a real read-while-write self-programming mechanism for downloading and uploading program code by the device itself. this feature allows flexible appli- cation software updates controlled by the devi ce using a boot loader application that reside in the boot loader section in the flash. the boot loader can use any available communication interface and associated protocol to read code and write (program) that code into the flash memory, or read out the program memory code. it has the capability to write into the entire flash, including the boot loader section. the boot loader can thus modify itself, and it can also erase itself from the code if the feature is not needed anymore.
277 8210b?avr?04/10 xmega d 23.10.1.1 application and boot loader sections the application and boot loader sections are different when it comes to self-programming. the application section is read-while-write (rww ) while the boot loader section is no read- while-write (nrww). here ?read-while-write? refers to the section being programmed (erased or written), not the section being read during a boot loader software update. whether the cpu can continue to run and execute code or is halted to stop program execution during a boot loader software update is depending on the flash address being programmed: ? when erasing or writing a page located inside the application section (rww), the boot loader section (nrww) can be read during the operation, thus the cpu can run and execute code from the boot loader section (nrww). ? when erasing or writing a page located inside the boot loader section (nrww), the cpu is halted during the entire operation and code cannot execute. the user signature row section is nrww, hence er asing or writing this section has the same properties as for the boot loader section. during an on-going programming, the software must ensure that the application section is not accessed. doing this will halt the program execut ion from the cpu. the user software can not read data located in the application section during a boot loader software operation. table 23-1. summary of rww and nrww functionality section being addressed by z-pointer during the programming? section that can be read during programming cpu halted read-while-write supported application section (rww) boot loader section (nrww) no ye s boot loader section (nrww) none yes no user signature row section (nrww) none yes no
278 8210b?avr?04/10 xmega d figure 23-1. read-while-write vs. no read-while-write 23.10.1.2 addressing the flash the z-pointer is used to hold the flash memory address for read and write access. the z pointer consists of the zl and zh registers in the r egister file, and rampz register for devices with more than 64k bytes for flash memory. for more details on the z-pointer refer to ?the x-, y- and z- registers? on page 10 . since the flash is word accessed and organized in pages, the z-pointer can be treated as hav- ing two sections. the least significant bits address the words within a page, while the most significant bits address the page within the flash. this is shown in figure 23-2 on page 279 . the word address in the page (fword) is held by the bits [wordmsb:1] in the z-pointer. the remaining bits [pagemsb:wordmsb+1] in the z-pointer holds the flash page address (fpage). together fword and fpage holds an absolute address to a word in the flash. for flash read operations (elpm and lmp), one byte is read at a time. for this the least signif- icant bit (bit 0) in the z-pointer is used to select the low byte or high byte in the word address. if this bit is 0, the low byte is read, and if this bit is 1 the high byte is read. the size of fword and fpage will depend on the page and flash size in the device, refer to each device datasheet for details on this. once a programming operation is initiated, the address is latched and the z-pointer can be updated and used for other operations. application section - read-while-write (rww) boot loader section - no read-while-write (nrww) z-pointer adresses rww section z-pointer adresses nrww section cpu is halted during the operation code located in nrww section can be read during the operation
279 8210b?avr?04/10 xmega d figure 23-2. flash addressing for self-programming 23.10.2 nvm flash commands the nvm commands that can be used for acce ssing the flash program memory, signature row and calibration row are listed in table 23-2 . for self-programming of the flash, the trigge r for action triggered commands is to set the cmdex bit in the nvm ctrla register (cmd ex). the read triggered commands are trig- gered by executing the (e)lpm instruction (lpm). the write triggered commands is triggered by a executing the spm instruction (spm). the change protected column indicate if the tr igger is protected by the configuration change protection (ccp). this is a special sequence to write/execute the trigger during self-program- ming, for more details refer to ?ccp - configuration change protection register? on page 13 . ccp is not required for external programming. the two last columns shows the address pointer used for addressing, and the source/destination data register. section 23.10.1.1 on page 277 through section 23.10.2.12 on page 283 explain in details the algorithm for each nvm operation. fpage fword 0/1 bit z-pointer pagemsb wordmsb 0 1 instruction word page page program memory word address within a page page address within the flash fword 00 01 02 pageend 00 01 02 flashend fpage low/high byte select for (e)lpm
280 8210b?avr?04/10 xmega d notes: 1. the flash range crc command used byte addressing of the flash. 2. will depend on the flash section (application or boot loader) that is actually addressed. 23.10.2.1 read flash the (e)lpm instruction is used to read one byte from the flash memory. 1. load the z-pointer with the byte address to read. 2. load the nvm command register (nvm cmd) with the no operation command. 3. execute the lpm instruction. the destination register will be loaded durin g the execution of the lpm instruction. 23.10.2.2 erase flash page buffer the erase flash page buffer command is used to erase the flash page buffer. 1. load the nvm cmd with the erase flash page buffer command. 2. set the command execute bit (nvmex) in the nvm control register a (nvm ctrla). this requires the timed ccp sequence during self-programming. table 23-2. flash self-programming commands cmd[6:0] group configuration description trigger cpu halted nvm busy change protected address pointer data register 0x00 no_operation no operation / read flash -/(e)lpm -/n n -/n -/ z-pointer -/rd flash page buffer 0x23 load_flash_buffer load flash page buffer spm n n n z-pointer r1:r0 0x26 erase_flash_buffer erase flash page buffer cmdex n y y z-pointer - flash 0x2b erase_flash_page erase flash page spm n/y (2) yyz-pointer - 0x02e write_flash_page write flash page spm n/y (2) yyz-pointer - 0x2f erase_write_flash_page erase & write flash page spm n/y (2) yyz-pointer - application section 0x20 erase_app erase application section spm y y y z-pointer - 0x22 erase_app_page erase application section page spm n y y z-pointer - 0x24 write_app_page write application section page spm n y y z-pointer - 0x25 erase_write_app_page erase & write application section page spm n y y z-pointer - boot loader section 0x2a erase_boot_page erase boot loader section page spm y y y z-pointer - 0x2c write_boot_page write boot loader section page spm y y y z-pointer - 0x2d erase_write_boot_page erase & write boot loader section page spm y y y z-pointer - user signature row 0x01 read_user_sig_row read user signature row lpm n n n z-pointer rd 0x18 erase_user_sig_row erase user signature row spm y y y - - 0x1a write_user_sig_row write user signature row spm y y y - - calibration row 0x02 read_calib_row read calibration row lpm n n n z-pointer rd
281 8210b?avr?04/10 xmega d the nvm busy (busy) flag in the nvm status register (nvm status) will be set until the page buffer is erased. 23.10.2.3 load flash page buffer the load flash page buffer command is used to load one word of data into the flash page buffer. 1. load the nvm cmd register with the load flash page buffer command. 2. load the z-pointer with the word address to write. 3. load the data word to be written into the r1:r0 registers. 4. execute the spm instruction. the spm instruction is not protected when performing a flash page buffer load. repeat step 2-4 until th e complete flash page bu ffer is loaded. unloaded locations will have the value 0xffff, and this is not a valid avr cpu opcode/instruction. 23.10.2.4 erase flash page the erase flash page command is used to erase one page in the flash. 1. load the z-pointer with the flash page address to erase. the page address must be written to pcpage. other bits in the z-po inter will be ignored du ring this operation. 2. load the nvm cmd register with the erase flash page command. 3. execute the spm instruction. this requires the timed ccp sequence during self- programming. the busy flag in the nvm status register will be set until the erase oper ation is finished. the flash section busy (fbusy) flag is set as long the flash is busy, and the application section cannot be accessed. 23.10.2.5 write flash page the write flash page command is used to write the flash page buffer into one flash page in the flash. 1. load the z-pointer with the flash page to write. the page address must be written to pcpage. other bits in the z-pointer will be ignored during this operation. 2. load the nvm cmd register with the write flash page command. 3. execute the spm instruction. this requires the timed ccp sequence during self- programming. the busy flag in the nvm status register will be set until the wr ite operation is finished. the fbusy flag is set as long the flash is busy, and the application section cannot be accessed. 23.10.2.6 erase application section the erase application command is used to erase the complete application section. 1. load the z-pointer to point anywhere in the application section. 2. load the nvm cmd register with the erase application section command 3. execute the spm instruction. this requires the timed ccp sequence during self- programming. the busy flag in the status register will be set until the operation is fi nished. the cpu will be halted during the complete execution of the command.
282 8210b?avr?04/10 xmega d 23.10.2.7 erase application section / boot loader section page the erase application section page erase and erase boot loader section page commands are used to erase one page in the application section or boot loader section. 1. load the z-pointer with the flash page address to erase. the page address must be written to zpage. other bits in the z-pointer will be igno red during th is operation. 2. load the nvm cmd register with the erase application/boot section page command. 3. execute the spm instruction. this requires the timed ccp sequence during self- programming. the busy flag in the nvm status register will be set until the erase oper ation is finished. the fbusy flag is set as long the flash is busy, and the application section cannot be accessed. 23.10.2.8 application section / boot loader section page write the write application section page and write boot loader section page commands are used to write the flash page buffer into one flash page in the application section or boot loader section. 1. load the z-pointer with the flash page to write. the page address must be written to pcpage. other bits in the z-pointer will be ignored during this operation. 2. load the nvm cmd register with the write application section/boot loader section page command. 3. execute the spm instruction. this requires the timed ccp sequence during self- programming. the busy flag in the nvm status register will be set until the wr ite operation is finished. the fbusy flag is set as long the flash is busy, and the application section cannot be accessed. an invalid page address in the z-pointer will abort the nvm command. the erase application section page command requires that the z-pointer addresses the application section, and the erase boot section page command requires that the z-pointer addresses the boot loader section. 23.10.2.9 erase & write application section / boot loader section page the erase & write application section page and erase & write boot loader section page com- mands are used to erase one flash page and then writ e the flash page buffer into that flash page in the application section or boot loader section, in one atomic operation. 1. load the z-pointer with the flash page to write. the page address must be written to pcpage. other bits in the z-pointer will be ignored during this operation. 2. load the nvm cmd register with the erase & write application section/boot loader section page command. 3. execute the spm instruction. this requires the timed ccp sequence during self- programming. the busy flag in the nvm status register wi ll be set until the operation is finished. the fbusy flag is set as long the flash is busy, and the application section cannot be accessed. an invalid page address in th e z-pointer will abort the nvm co mmand. the erase & write appli- cation section command requires that the z-pointer addresses the application section, and the erase & write boot section page command requires that the z-pointer addresses the boot loader section.
283 8210b?avr?04/10 xmega d 23.10.2.10 erase user signature row the erase user signature row command is used to erase the user signature row. 1. load the nvm cmd register with the erase user signature row command. 2. execute the spm instruction. this requires the timed ccp sequence during self- programming. the busy flag in the nvm status register will be set, and the cpu will be halted until the erase operation is finished. th e user signature row is nrww. 23.10.2.11 write user signature row the write signature row command is used to wr ite the flash page buffer into the user signa- ture row. 1. set up the nvm cmd register to write user signature row command. 2. execute the spm instruction. this requires the timed ccp sequence during self- programming. the busy flag in the nvm status register will be set until the operation is finished, and the cpu will be halted during the write operation. the flash page buffer will be cleared during the command execution after the write operation, but the cpu is not halted during this stage. 23.10.2.12 read user signature row / calibration row the read user signature row and red calibrati on row commands are used to read one byte from the user signature row or calibration row. 1. load the z-pointer with the byte address to read. 2. load the nvm cmd register with the re ad user signature row / calibration row command 3. execute the lpm instruction. the destination register will be loaded durin g the execution of the lpm instruction. 23.10.3 nvm fuse and lock bit commands the nvm flash commands that can be used for accessing the fuses and lock bits are listed in table 23-3 . for self-programming of the fuses and lock bits, the trigger for action triggered commands is to set the cmdex bit in the nvm ctrla register (cmdex). the read triggered commands are triggered by executing the (e)lpm instruction (lpm). the write triggered commands is trig- gered by a executing the spm instruction (spm). the change protected column indicate if the tr igger is protected by the configuration change protection (ccp) during self-programming. the two last columns shows the address pointer used for addressing, and the source/destination data register.
284 8210b?avr?04/10 xmega d section 23.10.3.1 on page 284 through section 23.10.3.2 on page 284 explain in details the algorithm for each nvm operation. 23.10.3.1 write lock bits write the write lock bits command is used to program the boot lock bits to a more secure settings from software. 1. load the nvm data0 register with the new lock bit value. 2. load the nvm cmd register with the write lock bit command. 3. set the cmdex bit in the nvm ctrla regist er. this requires the timed ccp sequence during self-programming. the busy flag in the nvm status register will be set until the command is finished. the cpu is halted during the complete execution of the command. this command can be executed from both the boot loader section and the application section. the eeprom and flash page buffer is automati cally erased when the lock bits are written. 23.10.3.2 read fuses the read fuses command is used to read the fuses from software. 1. load the nvm addr registers with the address to the fuse byte to read. 2. load the nvm cmd register with the read fuses command. 3. set the cmdex bit in the nvm ctrla regist er. this requires the timed ccp sequence during self-programming. the result will be available in the nvm data0 register. the cpu is halted during the complete execution of the command. 23.10.4 eeprom programming the eeprom can be read and writte n from application code in any part of the flash. its is both byte and page accessible. this means that eith er one byte or one page can be written to the eeprom at once. one byte is re ad from the eeprom during read. 23.10.4.1 addressing the eeprom the eeprom can be access ed through the nvm cont roller (i/o mapped), similar to the flash program memory, or it can be memory mapped into the data memory space to be accessed similar to sram. when accessing the eeprom through the nvm controller, the nvm address (addr) register is used to address the eeprom, while the nvm data (data) register is used to store or load eeprom data. table 23-3. fuse and lock bit commands cmd[6:0] group configuration description trigger cpu halted change protected address pointer data register nvm busy 0x00 no_operation no operation ? ? ? ? ? ? fuses and lock bits 0x07 read_fuses read fuses cmdex n n addr data y 0x08 write_lock_bits write lock bits cmdex n y addr ?y
285 8210b?avr?04/10 xmega d for eeprom page programming the addr register can be treated as having two section. the least significant bits address the bytes within a page, while the most significant bits address the page within the eeprom. this is shown in figure 23-3 on page 285 . the byte address in the page (e2byte) is held by the bits [1:bytemsb ] in the addr register. the remaining bits [pagemsb:bytemsb+1] in the addr register ho lds the eeprom page address (e2page). together e2byte and e2page hold s an absolute address to a byte in the eeprom. the size of e2word and e2page will depend on the page and flash size in the device, refer to the device datasheet for details on this. figure 23-3. i/o mapped eeprom addressing when eeprom memory mapping is enabled, loading a data byte into the eeprom page buffer can be performed through direct or indirect store instructions. only the least significant bits of the eeprom address are used to determine locations within the page buffer, but the complete memory mapped eeprom address is always required to ensure correct address mapping. reading from the eeprom can be d one directly using di rect or indirect lo ad instructions. when a memory mapped eeprom page buffer load operation is performed, the cpu is halted for 3 cycles before the next instruction is executed. when the eeprom is memory mapped, the eeprom page buffer load and eeprom read functionality from the nvm controller is disabled. 23.10.5 nvm eeprom commands the nvm flash commands that can be used fo r accessing the eeprom through the nvm con- troller are listed in table 23-4 . for self-programming of the eeprom the trigger for action trig gered commands is to set the cmdex bit in the nvm ctrla register (cmdex) . the read triggered command is triggered reading the nvm data0 register (data0). e2page e2byte bit nvm addr pagemsb bytemsb 0 data byte page page data memory byte address within a page page address within the eeprom e2byte 00 01 02 e2pageend e2page 00 01 02 e2end
286 8210b?avr?04/10 xmega d the change protected column indicate if the tr igger is protected by the configuration change protection (ccp) during self-programming. ccp is not required for external programming. the two last columns shows the address pointer used for addressing, and the source/destination data register. section 23.10.5.1 on page 286 through section 23.10.5.7 on page 287 explains in details the algorithm for each eeprom operation. 23.10.5.1 load eeprom page buffer the load eeprom page buffer command is used to load one byte into the eeprom page buffer. 1. load the nvm cmd register with the load eeprom page buffer command 2. load the nvm addr0 register with the address to write. 3. load the nvm data0 register with the data to write. this will trigger the command. repeat 2-3 until for the arbitrary number of bytes to be loaded into the page buffer. 23.10.5.2 erase eeprom page buffer the erase eeprom buffer comm and is used to erase the eeprom page buffer. 1. load the nvm cmd register with the erase eeprom buffer command. 2. set the cmdex bit in the nvm ctrla register. this requires the timed ccp sequence during self-programming. the busy flag in the nvm status register w ill be set until the o peration is finished. 23.10.5.3 epprom page erase the erase eeprom erase command is us ed to erase one eeprom page. 1. set up the nvm cmd register to erase eeprom page command. 2. load the nvm address register with the eeprom page to erase. 3. set the cmdex bit in the nvm ctrla register. this requires the timed ccp sequence during self-programming. the busy flag in the nvm status register w ill be set until the o peration is finished. table 23-4. eeprom self-progr amming commands cmd[6:0] group configuration description trigger cpu halted change protected address pointer data register nvm busy 0x00 no_operation no operation ? ? ? ? ? ? eeprom page buffer 0x33 load_eeprom_buffer load eeprom page buffer data0 n y addr data0 n 0x36 erase_eeprom _buffer erase eeprom page buffer cmdex n y ? ?y eeprom y 0x32 erase_eeprom_page erase eeprom page cmdex n y addr ?y 0x34 write_eeprom_page write eeprom page cmdex n y addr ?y 0x35 erase_write_eeprom_page erase & write eeprom page cmdex n y addr ?y 0x30 erase_eeprom erase eeprom cmdex n y ? ?y 0x06 read_eeprom read eeprom cmdex n y addr data0 n
287 8210b?avr?04/10 xmega d the page erase commands will only erase the locations that correspond with the loaded and tagged locations in the eeprom page buffer. 23.10.5.4 write eeprom page the write eeprom page co mmand is used to write all locati ons that is load ed in the eeprom page buffer into one page in eeprom. only the locations that are loaded and tagged in the eeprom page buffer will be written. 1. load the nvm cmd register with the write eeprom page command. 2. load the nvm addr register with the address for eeprom page to write. 3. set the cmdex bit in nvm ctrla register. this requires the timed ccp sequence during self-programming. the busy flag in the nvm status register w ill be set until the o peration is finished. 23.10.5.5 erase & write eeprom page the erase & write eeprom page command is used to first erase an eeprom page and write the eeprom page buffer into that page in eeprom, in one atomic operation. 1. load the nvm cmd register with the erase & write eeprom page command. 2. load the nvm addr register with the address for eeprom page to write. 3. set the cmdex bit in nvm ctrla register. this requires the timed ccp sequence during self-programming. the busy flag in the nvm status register w ill be set until the o peration is finished. 23.10.5.6 erase eeprom the erase eeprom co mmand is used to erase all the loca tions in all eeprom pages that cor- responds the loaded a nd tagged locations in the eeprom page buffer. 1. set up the nvm cmd regist er to erase epprom command. 2. set the cmdex bit in nvm ctrla register. this requires the timed ccp sequence during self-programming. the busy flag in the nvm status register w ill be set until the o peration is finished. 23.10.5.7 read epprom the read eeprom command is used to read one byte from the eeprom, 1. load the nvm cmd register with the read epprom command. 2. load the nvm addr register with the address to read. 3. set the cmdex bit in nvm ctrla register. this requires the timed ccp sequence during self-programming. the data byte read will be av ailable in the nvm data0.
288 8210b?avr?04/10 xmega d 23.11 external programming external programming is the method for programming non volatile code and data into the device from an external programmer or debugger. this can be done both in-system (in-system pro- gramming) or in mass production programming. the only restrictions on clock speed and voltage is the maximum and minimum operating conditions for the device. refer to the device datasheet for details on this. for external programming the dev ice is accessed through the pdi and pdi controller, using the pdi physical connection. for details on pdi and how to enable and use the physical interface, refer to ?program and debug interface? on page 352 . the remainder of this section assumes that the correct physical connection to the pdi is enabled. through the pdi, the external programmer access all nvm memories and nvm controller using the pdi bus. doing this all data and program memory spaces are mapped into the linear pdi memory space. figure 23-4 on page 289 shows the pdi memory space and the base address for each memory space in the device.
289 8210b?avr?04/10 xmega d figure 23-4. memory map for pdi accessing the data and program memories. flash_base = 0x0800000 epprom_base = 0x08c0000 fuse_base = 0x08f0020 datamem_base = 0x1000000 app_base = flash_base boot_base = flash_base + size_appl prod_signature_base = 0x008e0200 user_signature_base = 0x008e0400 0x0000000 fuses application section 16 mb boot section 0x0800000 0x08f0020 top=0x1ffffff eeprom 0x08e0200 srow 0x08c0000 0x08c1000 datamem (mapped io/sram) 16 mb 0x1000000 1 byte
290 8210b?avr?04/10 xmega d 23.11.1 enabling external programming interface nvm programming from the pdi requires enabling, and this is one the following fashion. 1. load the reset register in the pdi with 0x59 - th e reset signature. 2. load the correct nvm key in the pdi. 3. poll nvmen in the pdi status regist er (pdi status) until nvmen is set. when the nvmen bit in the pdi status register is set the nvm interface is active from the pdi. 23.11.2 nvm programming 23.11.2.1 addressing the nvm when the pdi nvm interface is enabled, all th e memories in the device is memory-mapped in the pdi address space. for the reminder of this section all references to reading and writing data or program memory addresses from pdi, refer to the memory map as shown in figure 23-4 on page 289 . the pdi is always using byte addressing, hence all memory addresses must be byte addresses. when filling the flash or eeprom page buffers, on ly the least significant bits of the address are used to determine locations within the page buffer. still, the complete memory mapped address for the flash or eeprom page is required to ensure correct address mapping. 23.11.2.2 nvm busy during programming (page erase and page write) when the nvm is busy, the complete nvm is blocked for reading. 23.11.3 nvm commands the nvm commands that can be used for accessing the nvm memories from external program- ming are listed in table 23-5 . this is a super-set of the commands available for self- programming. for external programming, the trigger for action triggered commands is to set the cmdex bit in the nvm ctrla register (cmdex). the read triggered commands are triggered by a direct or indirect load instruction (lds or ld) from the pdi (pdi read). the write triggered com- mands is triggered by a direct or indirect store instruction (sts or st) from the pdi (pdi write). section 23.11.3.1 on page 292 through section 23.11.3.9 on page 293 explains in detail the algorithm for each nvm operation. the commands are protected by the lock bits, and if read and write lock is set, only the chip erase and flash crc commands are available.
291 8210b?avr?04/10 xmega d table 23-5. nvm commands available for external programming notes: 1. if the eesave fuse is programmed t he eeprom is preserved during chip erase. cmd[6:0] commands / operation trigger change protected nvm busy 0x00 no operation --- 0x40 chip erase (1) cmdex y y 0x43 read nvm pdi read n n flash page buffer 0x23 load flash page buffer pdi write n n 0x26 erase flash page buffer cmdex y y flash 0x2b erase flash page pdi write n y 0x02e flash page write pdi write n y 0x2f erase & write flash page pdi write n y application section 0x20 erase application section pdi write n y 0x22 erase application section page pdi write n y 0x24 write application section page pdi write n y 0x25 erase & write application section page pdi write n y boot loader section 0x68 erase boot section pdi write n y 0x2a erase boot loader section page pdi write n y 0x2c write boot loader section page pdi write n y 0x2d erase & write boot loader section page pdi write n y calibration and user signature sections 0x03 read user signature row pdi read n n 0x18 erase user signature row pdi write n y 0x1a write user signature row pdi write n y 0x02 read calibration row pdi read n n fuses and lock bits 0x07 read fuse pdi read n n 0x4c write fuse pdi write n y 0x08 write lock bits cmdex y y eeprom page buffer 0x33 load eeprom page buffer pdi write n n 0x36 erase eeprom page buffer cmdex y y eeprom 0x30 erase eeprom cmdex y y 0x32 erase eeprom page pdi write n y 0x34 write eeprom page pdi write n y 0x35 erase & write eeprom page pdi write n y 0x06 read eeprom pdi read n n
292 8210b?avr?04/10 xmega d 23.11.3.1 chip erase the chip erase command is used to eras e the flash program me mory, eeprom and lock bits. erasing of the eeprom depend eesave fuse setting, refer to ?fusebyte5 - non-vola- tile memory fuse byte 5? on page 32 for details. the user signature row, calibration row and fuses are not effected. 1. load the nvm cmd register with chip erase command. 2. set the cmdex bit in nvm ctrla register. this requires the timed ccp sequence during self-programming. once this operation starts the pdibus between the pdi controller and the nvm is disabled, and the nvmen bit in the pdi status register is cleared until the operation is finished. poll the nvmen bit until this is set again, indicting the pdibus is enabled. the busy flag in the nvm status register w ill be set until the o peration is finished. 23.11.3.2 read nvm the read nvm command is used to read the flash, eeprom, fu ses, and sig nature and cali- bration row sections. 1. load the nvm cmd register with the read nvm command. 2. read the selected memory address by doing a pdi read operation. dedicated read eeprom, read fuse and read signature ro w and read calibration row commands are also available fo r the various memory sections. the algorithm for these com- mands are the same as for the nvm read command. 23.11.3.3 erase page buffer the erase flash page buffer and erase eeprom page buffer commands are used to erase the flash and eeprom page buffers. 1. load the nvm cmd register with the erase flash/eeprom pa ge buffer command. 2. set the cmdex bit in the nvm ctrla register. this requires the timed ccp sequence during self-programming. the busy flag in the nvm status register w ill be set until the o peration is completed. 23.11.3.4 load page buffer the load flash page buffer and load eeprom page buffer commands are used to load one byte of data into the flash and eeprom page buffers. 1. load the nvm cmd register with the load flash/eeprom pa ge buffer command. 2. write the selected memory address by doing a pdi write operation. since the flash page buffer is word accessing and the pdi uses byte addressing, the pdi must write the flash page buffer in correct order. for the write operation, the low-byte of the word location must be written before the high-byte. the low-byte is then written into the temporary register. the pdi then writes the high-byte of the word location, and the low-byte is then written into the word location page bu ffer in the same clock cycle. the pdi interface is automatically halted, before the next pdi instruction can be executed. 23.11.3.5 erase page the erase application section page, erase b oot loader section page, erase user signature row and erase eeprom page commands are used to erase one page in the selected memory space.
293 8210b?avr?04/10 xmega d 1. load the nvm cmd register with erase application section/boot loader section/user signature row/eeprom page command. 2. write the selected page by doing a pdi write. the page is written by addressing any byte location within the page. the busy flag in the nvm status register w ill be set until the o peration is finished. 23.11.3.6 write page the write application section page, write boot loader section page, write user signature row and write eeprom page is used to write a loaded flash/eeprom page buffer into the selected memory space 1. load the nvm cmd register with write application section/boot loader section/user signature row/eeprom page command. 2. write the selected page by doing a pdi write. the page is written by addressing any byte location within the page. the busy flag in the nvm status register w ill be set until the o peration is finished. 23.11.3.7 erase & write page the erase & write application section page, erase & write boot loader section page, and erase & write eeprom page is used to erase one page and then write a loaded flash/eeprom page buffer into that page in the selected memory space, in one atomic operation. 1. load the nvm cmd register with erase & write application section/boot loader sec- tion/user signature ro w/eeprom page command. 2. write the selected page by doing a pdi write. the page is written by addressing any byte location within the page. the busy flag in the nvm status register w ill be set until the o peration is finished. 23.11.3.8 erase application/ boot loader/ eeprom section the erase application section, erase boot loader section and erase eeprom section com- mand is used to erase the complete section selected. 1. load the nvm cmd register with erase application/ boot/ eeprom section command 2. write the selected section by doing a pdi write. the section is written by addressing any byte location within the section. the busy flag in the nvm status register w ill be set until the o peration is finished. 23.11.3.9 write fuse/ lock bit the write fuse and write lock bit command is used to write the fuses and the lock bits to a more secure setting. 1. load the nvm cmd register with the write fuse/ lock bit command. 2. write the selected fuse or lock bits by doing a pdi write operation. the busy flag in the nvm status register will be set until the command is finished. for lock bit write the lock bit write command can also be used.
294 8210b?avr?04/10 xmega d 23.12 register description refer to ?register summary - nvm controller? on page 46 for complete register description on the nvm controller. refer to ?register description - pdi control and status register? on page 367 for complete reg- ister description on the pdi. 23.13 register summary refer to ?register summary - nvm controller? on page 46 for complete register summary on the nvm controller. refer to ?register summary? on page 369 for complete register summary on the pdi.
295 8210b?avr?04/10 xmega d 24. peripheral modu le address map the address maps show the base address for each peripheral and module in xmega. all peripherals and modules are not present in all xmega devices, refer to device datasheet for the peripherals module address map for a specific device. table 24-1. peripheral module address map base address name description page 0x0000 gpio general purpose io registers 48 0x0010 vport0 virtual port 0 148 0x0014 vport1 virtual port 1 0x0018 vport2 virtual port 2 0x001c vport3 virtual port 3 0x0030 cpu cpu 17 0x0040 clk clock control 94 0x0048 sleep sleep controller 101 0x0050 osc oscillator control 94 0x0060 dfllrc32m dfll for the 32 mhz internal rc oscillator 94 0x0068 dfllrc2m dfll for the 2 mhz rc oscillator 0x0070 pr power reduction 101 0x0078 rst reset controller 110 0x0080 wdt watch-dog timer 116 0x0090 mcu mcu control 48 0x00a0 pmic programmable multilevel interrupt controller 122 0x00b0 portcfg port configuration 148 0x0180 evsys event system 75 0x01c0 nvm non volatile memory (nvm) controller 46 0x0200 adca analog to digital converter on port a 315 0x0380 aca analog comparator pair on port a 336 0x0400 rtc real time counter 191 0x0480 twic two wire interface on port c 243 0x0600 porta port a 148 0x0620 portb port b 0x0640 portc port c 0x0660 portd port d 0x0680 porte port e 0x06a0 portf port f 0x06e0 porth port h 0x0700 portj port j 0x0720 portk port k 0x07c0 portq port q 0x07e0 portr port r 0x0800 tcc0 timer/counter 0 on port c 184 0x0840 tcc1 timer/counter 1 on port c 0x0880 awexc advanced wavefo rm extension on port c 187 0x0890 hiresc high resolution extension on port c 189 0x08a0 usartc0 usart 0 on port c 270 0x08c0 spic serial peripheral interface on port c 249 0x08f8 ircom infrared communication module 274 0x0900 tcd0 timer/counter 0 on port d 184 0x09a0 usartd0 usart 0 on port d 270 0x09c0 spid serial peripheral interface on port d 249 0x0a00 tce0 timer/counter 0 on port e 184 0x0aa0 usarte0 usart 0 on port e 270 0x0b00 tcf0 timer/counter 0 on port f 184 0x0ba0 usartf0 usart 0 on port f 270
296 8210b?avr?04/10 xmega d 25. instruction set summary mnemonics operands description operation flags #clocks arithmetic and logic instructions add rd, rr add without carry rd rd + rr z,c,n,v,s,h 1 adc rd, rr add with carry rd rd + rr + c z,c,n,v,s,h 1 adiw rd, k add immediate to word rd rd + 1:rd + k z,c,n,v,s 2 sub rd, rr subtract without carry rd rd - rr z,c,n,v,s,h 1 subi rd, k subtract immediate rd rd - k z,c,n,v,s,h 1 sbc rd, rr subtract with carry rd rd - rr - c z,c,n,v,s,h 1 sbci rd, k subtract immediate with carry rd rd - k - c z,c,n,v,s,h 1 sbiw rd, k subtract immediate from word rd + 1:rd rd + 1:rd - k z,c,n,v,s 2 and rd, rr logical and rd rd ? rr z,n,v,s 1 andi rd, k logical and with immediate rd rd ? k z,n,v,s 1 or rd, rr logical or rd rd v rr z,n,v,s 1 ori rd, k logical or with immediate rd rd v k z,n,v,s 1 eor rd, rr exclusive or rd rd rr z,n,v,s 1 com rd one?s complement rd $ff - rd z,c,n,v,s 1 neg rd two?s complement rd $00 - rd z,c,n,v,s,h 1 sbr rd,k set bit(s) in register rd rd v k z,n,v,s 1 cbr rd,k clear bit(s) in register rd rd ? ($ffh - k) z,n,v,s 1 inc rd increment rd rd + 1 z,n,v,s 1 dec rd decrement rd rd - 1 z,n,v,s 1 tst rd test for zero or minus rd rd ? rd z,n,v,s 1 clr rd clear register rd rd rd z,n,v,s 1 ser rd set register rd $ff none 1 mul rd,rr multiply unsigned r1:r0 rd x rr (uu) z,c 2 muls rd,rr multiply signed r1:r0 rd x rr (ss) z,c 2 mulsu rd,rr multiply signed with unsigned r1:r0 rd x rr (su) z,c 2 fmul rd,rr fractional multiply unsigned r1:r0 rd x rr<<1 (uu) z,c 2 fmuls rd,rr fractional multiply signed r1:r0 rd x rr<<1 (ss) z,c 2 fmulsu rd,rr fractional multiply signed with unsigned r1:r0 rd x rr<<1 (su) z,c 2 des k data encryption if (h = 0) then r15:r0 else if (h = 1) then r15:r0 encrypt(r15:r0, k) decrypt(r15:r0, k) 1/2 branch instructions rjmp k relative jump pc pc + k + 1 none 2 ijmp indirect jump to (z) pc(15:0) pc(21:16) z, 0 none 2 eijmp extended indirect jump to (z) pc(15:0) pc(21:16) z, eind none 2 jmp k jump pc k none 3 rcall k relative call subroutine pc pc + k + 1 none 2 / 3 (1) icall indirect call to (z) pc(15:0) pc(21:16) z, 0 none 2 / 3 (1) eicall extended indirect call to (z) pc(15:0) pc(21:16) z, eind none 3 (1)
297 8210b?avr?04/10 xmega d call k call subroutine pc k none 3 / 4 (1) ret subroutine return pc stack none 4 / 5 (1) reti interrupt return pc stack i 4 / 5 (1) cpse rd,rr compare, skip if equal if (rd = rr) pc pc + 2 or 3 none 1 / 2 / 3 cp rd,rr compare rd - rr z,c,n,v,s,h 1 cpc rd,rr compare with carry rd - rr - c z,c,n,v,s,h 1 cpi rd,k compare with immediate rd - k z,c,n,v,s,h 1 sbrc rr, b skip if bit in register cleared if (rr(b) = 0) pc pc + 2 or 3 none 1 / 2 / 3 sbrs rr, b skip if bit in register set if (rr(b) = 1) pc pc + 2 or 3 none 1 / 2 / 3 sbic a, b skip if bit in i/o register cleared if (i/o(a,b) = 0) pc pc + 2 or 3 none 2 / 3 / 4 sbis a, b skip if bit in i/o register set if (i/o(a,b) =1) pc pc + 2 or 3 none 2 / 3 / 4 brbs s, k branch if status flag set if (sreg(s) = 1) then pc pc + k + 1 none 1 / 2 brbc s, k branch if status flag cleared if (sreg(s) = 0) then pc pc + k + 1 none 1 / 2 breq k branch if equal if (z = 1) then pc pc + k + 1 none 1 / 2 brne k branch if not equal if (z = 0) then pc pc + k + 1 none 1 / 2 brcs k branch if carry set if (c = 1) then pc pc + k + 1 none 1 / 2 brcc k branch if carry cleared if (c = 0) then pc pc + k + 1 none 1 / 2 brsh k branch if same or higher if (c = 0) then pc pc + k + 1 none 1 / 2 brlo k branch if lower if (c = 1) then pc pc + k + 1 none 1 / 2 brmi k branch if minus if (n = 1) then pc pc + k + 1 none 1 / 2 brpl k branch if plus if (n = 0) then pc pc + k + 1 none 1 / 2 brge k branch if greater or equal, signed if (n v= 0) then pc pc + k + 1 none 1 / 2 brlt k branch if less than, signed if (n v= 1) then pc pc + k + 1 none 1 / 2 brhs k branch if half carry flag set if (h = 1) then pc pc + k + 1 none 1 / 2 brhc k branch if half carry flag cleared if (h = 0) then pc pc + k + 1 none 1 / 2 brts k branch if t flag set if (t = 1) then pc pc + k + 1 none 1 / 2 brtc k branch if t flag cleared if (t = 0) then pc pc + k + 1 none 1 / 2 brvs k branch if overflow flag is set if (v = 1) then pc pc + k + 1 none 1 / 2 brvc k branch if overflow flag is cleared if (v = 0) then pc pc + k + 1 none 1 / 2 brie k branch if interrupt enabled if (i = 1) then pc pc + k + 1 none 1 / 2 brid k branch if interrupt disabled if (i = 0) then pc pc + k + 1 none 1 / 2 data transfer instructions mov rd, rr copy register rd rr none 1 movw rd, rr copy register pair rd+1:rd rr+1:rr none 1 ldi rd, k load immediate rd k none 1 lds rd, k load direct from data space rd (k) none 2 / 3 (1)(2) ld rd, x load indirect rd (x) none 1 / 2 (1)(2) ld rd, x+ load indirect and post-increment rd x (x) x + 1 none 1 (1)(2) ld rd, -x load indirect and pre-decrement x x - 1, rd (x) x - 1 (x) none 2 / 3 (1)(2) ld rd, y load indirect rd (y) (y) none 1 / 2 (1)(2) ld rd, y+ load indirect and post-increment rd y (y) y + 1 none 1 / 2 (1)(2) mnemonics operands description operation flags #clocks
298 8210b?avr?04/10 xmega d ld rd, -y load indirect and pre-decrement y rd y - 1 (y) none 2 / 3 (1)(2) ldd rd, y+q load indirect with displacement rd (y + q) none 2 / 3 (1)(2) ld rd, z load indirect rd (z) none 1 / 2 (1)(2) ld rd, z+ load indirect and post-increment rd z (z), z+1 none 1 / 2 (1)(2) ld rd, -z load indirect and pre-decrement z rd z - 1, (z) none 2 / 3 (1)(2) ldd rd, z+q load indirect with displacement rd (z + q) none 2 / 3 (1)(2) sts k, rr store direct to data space (k) rd none 2 (1) st x, rr store indirect (x) rr none 1 (1) st x+, rr store indirect and post-increment (x) x rr, x + 1 none 1 (1) st -x, rr store indirect and pre-decrement x (x) x - 1, rr none 2 (1) st y, rr store indirect (y) rr none 1 (1) st y+, rr store indirect and post-increment (y) y rr, y + 1 none 1 (1) st -y, rr store indirect and pre-decrement y (y) y - 1, rr none 2 (1) std y+q, rr store indirect with displacement (y + q) rr none 2 (1) st z, rr store indirect (z) rr none 1 (1) st z+, rr store indirect and post-increment (z) z rr z + 1 none 1 (1) st -z, rr store indirect and pre-decrement z z - 1 none 2 (1) std z+q,rr store indirect with displacement (z + q) rr none 2 (1) lpm load program memory r0 (z) none 3 lpm rd, z load program memory rd (z) none 3 lpm rd, z+ load program memory and post-increment rd z (z), z + 1 none 3 elpm extended load program memory r0 (rampz:z) none 3 elpm rd, z extended load program memory rd (rampz:z) none 3 elpm rd, z+ extended load program memory and post- increment rd z (rampz:z), z + 1 none 3 spm store program memory (rampz:z) r1:r0 none - spm z+ store program memory and post-increment by 2 (rampz:z) z r1:r0, z + 2 none - in rd, a in from i/o location rd i/o(a) none 1 out a, rr out to i/o location i/o(a) rr none 1 push rr push register on stack stack rr none 1 (1) pop rd pop register from stack rd stack none 2 (1) bit and bit-test instructions lsl rd logical shift left rd(n+1) rd(0) c rd(n), 0, rd(7) z,c,n,v,h 1 lsr rd logical shift right rd(n) rd(7) c rd(n+1), 0, rd(0) z,c,n,v 1 mnemonics operands description operation flags #clocks
299 8210b?avr?04/10 xmega d notes: 1. cycle times for data memo ry accesses assume internal memo ry accesses, and are not valid for accesses via the external ram interface. 2. extra cycle when accessing internal sram. rol rd rotate left through carry rd(0) rd(n+1) c c, rd(n), rd(7) z,c,n,v,h 1 ror rd rotate right through carry rd(7) rd(n) c c, rd(n+1), rd(0) z,c,n,v 1 asr rd arithmetic shift right rd(n) rd(n+1), n=0..6 z,c,n,v 1 swap rd swap nibbles rd(3..0) ? rd(7..4) none 1 bset s flag set sreg(s) 1sreg(s)1 bclr s flag clear sreg(s) 0sreg(s)1 sbi a, b set bit in i/o register i/o(a, b) 1 none 1 cbi a, b clear bit in i/o register i/o(a, b) 0 none 1 bst rr, b bit store from register to t t rr(b) t 1 bld rd, b bit load from t to register rd(b) t none 1 sec set carry c 1c1 clc clear carry c 0c1 sen set negative flag n 1n1 cln clear negative flag n 0n1 sez set zero flag z 1z1 clz clear zero flag z 0z1 sei global interrupt enable i 1i1 cli global interrupt disable i 0i1 ses set signed test flag s 1s1 cls clear signed test flag s 0s1 sev set two?s complement overflow v 1v1 clv clear two?s complement overflow v 0v1 set set t in sreg t 1t1 clt clear t in sreg t 0t1 seh set half carry flag in sreg h 1h1 clh clear half carry flag in sreg h 0h1 mcu control instructions break break (see specific descr. for break) none 1 nop no operation none 1 sleep sleep (see specific descr. for sleep) none 1 wdr watchdog reset (see specific descr. for wdr) none 1 mnemonics operands description operation flags #clocks
300 8210b?avr?04/10 xmega d 26. datasheet revision history 26.1 8210b ?04/10 26.2 8210a ? 08/09 1. removed spike detector section form the datasheet and updated the book. 2. updated ?adc - analog to digital converter? on page 224 . 3. editing updates. 1. initial revision
i 8210b?avr?04/10 xmega d table of contents 1 about the manual ....... ................ ................. ................ ................. ............ 2 1.1 reading the manual ..........................................................................................2 1.2 resources .........................................................................................................2 1.3 recommended reading ....................................................................................2 2 overview ............ ................ ................ ............... .............. .............. ............ 3 2.1 block diagram ...................................................................................................4 3 avr cpu ............... .............. .............. ............... .............. .............. ............ 5 3.1 features ............................................................................................................5 3.2 overview ............................................................................................................5 3.3 architectural overview .......................................................................................5 3.4 alu - arithmetic logic unit ...............................................................................7 3.5 program flow ....................................................................................................7 3.6 instruction execution timing .............................................................................8 3.7 status register ..................................................................................................9 3.8 stack and stack pointer ....................................................................................9 3.9 register file ......................................................................................................9 3.10 ramp and extended indirect registers ..........................................................11 3.11 accessing 16-bits registers ............................................................................12 3.12 configuration change protection ....................................................................12 3.13 fuse lock ........................................................................................................13 3.14 register description ........................................................................................13 3.15 register summary ...........................................................................................17 4 memories ............... .............. .............. ............... .............. .............. .......... 18 4.1 features ..........................................................................................................18 4.2 overview ..........................................................................................................18 4.3 flash program memory ...................................................................................18 4.4 fuses and lockbits ..........................................................................................20 4.5 data memory ...................................................................................................21 4.6 internal sram .................................................................................................21 4.7 eeprom ............... ................ ................ ................ ................ ................ ..........21 4.8 i/o memory ......................................................................................................21 4.9 memory timing ................................................................................................22 4.10 device id .........................................................................................................22
ii 8210b?avr?04/10 xmega d 4.11 io memory protection ......................................................................................22 4.12 register description - nvm controller ............................................................22 4.13 register description ? fuses and lockbit .......................................................28 4.14 register description - production signature row ...........................................34 4.15 register description ? general purpose i/o memory .....................................38 4.16 register description ? mcu control ...............................................................39 4.17 register summary - nvm controller ...............................................................41 4.18 register summary - fuses and lockbits .........................................................41 4.19 register summary - production signature row ..............................................42 4.20 register summary - general purpose i/o registers ......................................43 4.21 register summary - mcu control ...................................................................43 4.22 interrupt vector summary - nvm controller ....................................................43 5 event system ........ .............. .............. ............... .............. .............. .......... 44 5.1 features ..........................................................................................................44 5.2 overview ..........................................................................................................44 5.3 events ..............................................................................................................45 5.4 event routing network ....................................................................................46 5.5 event timing ....................................................................................................47 5.6 filtering ............................................................................................................48 5.7 quadrature decoder ........................................................................................48 5.8 register description ........................................................................................50 5.9 register summary ...........................................................................................54 6 system clock and clock options ................ ................. .............. .......... 55 6.1 features ..........................................................................................................55 6.2 overview ..........................................................................................................55 6.3 clock distribution .............................................................................................56 6.4 clock sources .................................................................................................57 6.5 system clock selection and prescalers ..........................................................59 6.6 pll with 1-31x multiplication factor ................................................................60 6.7 dfll 2 mhz and dfll 32 mhz ......................................................................60 6.8 external clock source failure monitor ............................................................61 6.9 register description - clock ............................................................................63 6.10 register description - oscillator ......................................................................66 6.11 register description - dfll32m/dfll2m ......................................................71 6.12 register summary - clock ...............................................................................73
iii 8210b?avr?04/10 xmega d 6.13 register summary - oscillator .........................................................................73 6.14 register summary - dfll32m/dfll2m .........................................................73 6.15 crystal oscillator failure interrupt ve ctor summary .......................................73 7 power management and sleep .... ................ ................. .............. .......... 74 7.1 features ..........................................................................................................74 7.2 overview ..........................................................................................................74 7.3 sleep modes ....................................................................................................74 7.4 power reduction registers .............................................................................76 7.5 register description ? sleep ...........................................................................76 7.6 register description ? power reduction .........................................................77 7.7 register summary - sleep ..............................................................................79 7.8 register summary - power reduction ............................................................79 8 reset system ........ .............. .............. ............... .............. .............. .......... 80 8.1 features ..........................................................................................................80 8.2 overview ..........................................................................................................80 8.3 reset sequence ..............................................................................................82 8.4 reset sources .................................................................................................82 8.5 register description ........................................................................................87 8.6 register summary ...........................................................................................88 9 wdt ? watchdog timer ......... .............. .............. .............. .............. ........ 89 9.1 features ..........................................................................................................89 9.2 overview ..........................................................................................................89 9.3 normal mode operation ..................................................................................89 9.4 window mode operation .................................................................................90 9.5 watchdog timer clock .....................................................................................90 9.6 configuration protection and lock ..................................................................90 9.7 registers description ......................................................................................91 9.8 register summary ...........................................................................................94 10 interrupts and programmabl e multi-level interrupt controller .......... 95 10.1 features ..........................................................................................................95 10.2 overview ..........................................................................................................95 10.3 operation .........................................................................................................95 10.4 interrupts .........................................................................................................96 10.5 interrupt level ...................................................................................................97 10.6 interrupt priority ...............................................................................................97
iv 8210b?avr?04/10 xmega d 10.7 moving interrupts between application and boot section ...............................99 10.8 register description ........................................................................................99 10.9 register summary .........................................................................................100 11 i/o ports ............... .............. .............. .............. .............. .............. ........... 101 11.1 features ........................................................................................................101 11.2 overview ........................................................................................................101 11.3 using the i/o pin ...........................................................................................102 11.4 i/o pin configuration .....................................................................................103 11.5 reading the pin value ...................................................................................105 11.6 input sense configuration .............................................................................106 11.7 port interrupt ..................................................................................................107 11.8 port event ......................................................................................................108 11.9 alternate port functions ................................................................................108 11.10 clock and event output .................................................................................109 11.11 multi-configuration .........................................................................................109 11.12 virtual registers ............................................................................................110 11.13 register description ? ports ..........................................................................110 11.14 register description ? multiport configuration ..............................................115 11.15 register description ? virtual port ................................................................118 11.16 register summary ? ports ............................................................................120 11.17 register summary ? port configuration ........................................................120 11.18 register summary ? virtual ports .................................................................120 11.19 interrupt vector summary - ports ..................................................................120 12 tc - 16-bit timer/counter .. ............. .............. .............. .............. ........... 121 12.1 features ........................................................................................................121 12.2 overview ........................................................................................................121 12.3 block diagram ...............................................................................................123 12.4 clock and event sources ..............................................................................125 12.5 double buffering ............................................................................................125 12.6 counter operation .........................................................................................127 12.7 capture channel ...........................................................................................128 12.8 compare channel .........................................................................................131 12.9 interrupts and events .....................................................................................135 12.10 timer/counter commands ............................................................................136 12.11 register description ......................................................................................137
v 8210b?avr?04/10 xmega d 12.12 register summary .........................................................................................147 12.13 interrupt vector summary .............................................................................147 13 hi-res - high resolution extension .......... ................ .............. ........... 148 13.1 features ........................................................................................................148 13.2 overview ........................................................................................................148 13.3 register description ......................................................................................149 13.4 register summary .........................................................................................149 14 awex ? advanced waveform extension ......... .............. ............ ........ 150 14.1 features ........................................................................................................150 14.2 overview ........................................................................................................150 14.3 port override .................................................................................................151 14.4 dead time insertion ......................................................................................153 14.5 pattern generation ........................................................................................154 14.6 fault protection .............................................................................................155 14.7 register description ......................................................................................156 14.8 register summary .........................................................................................161 15 rtc - real time counter .. .............. .............. .............. .............. ........... 162 15.1 features ........................................................................................................162 15.2 overview ........................................................................................................162 15.3 register description ......................................................................................163 15.4 register summary .........................................................................................168 15.5 interrupt vector summary .............................................................................168 16 twi ? two wire interface ... .............. ............... .............. .............. ........ 169 16.1 features ........................................................................................................169 16.2 overview ........................................................................................................169 16.3 general twi bus concepts ...........................................................................170 16.4 twi bus state logic ......................................................................................176 16.5 twi master operation ...................................................................................177 16.6 twi slave operation .....................................................................................179 16.7 enabling external driver interface .................................................................180 16.8 register description - twi ............................................................................181 16.9 register description - twi master ................................................................181 16.10 register description - twi slave ..................................................................187 16.11 register summary - twi ...............................................................................192 16.12 register summary - twi master ...................................................................192
vi 8210b?avr?04/10 xmega d 16.13 register summary - twi slave .....................................................................192 16.14 interrupt vector summary .............................................................................192 17 spi ? serial peripheral interface ......... .............. .............. ............ ........ 193 17.1 features ........................................................................................................193 17.2 overview ........................................................................................................193 17.3 master mode ..................................................................................................194 17.4 slave mode ....................................................................................................194 17.5 data modes ...................................................................................................195 17.6 register description ......................................................................................196 17.7 register summary .........................................................................................198 17.8 spi interrupt vectors ......................................................................................198 18 usart ............. ................. ................ .............. .............. .............. ........... 199 18.1 features ........................................................................................................199 18.2 overview ........................................................................................................199 18.3 clock generation ...........................................................................................201 18.4 frame formats ..............................................................................................204 18.5 usart initialization .......................................................................................205 18.6 data transmission - the usart transmitter ...............................................205 18.7 data reception - the usart receiver ........................................................206 18.8 asynchronous data reception ......................................................................207 18.9 the impact of fractional baud rate generation ...........................................210 18.10 usart in master spi mode ..........................................................................211 18.11 usart spi vs. spi .......................................................................................211 18.12 multi-processor communication mode ..........................................................212 18.13 ircom mode of operation ............................................................................213 18.14 register description ......................................................................................213 18.15 register summary .........................................................................................219 18.16 interrupt vector summary .............................................................................219 19 ircom - ir communication module .............. .............. .............. ........ 220 19.1 features ........................................................................................................220 19.2 overview ........................................................................................................220 19.3 registers description ....................................................................................222 19.4 register summary .........................................................................................223 20 adc - analog to digital converter ......... ................. ................ ........... 224 20.1 features ........................................................................................................224
vii 8210b?avr?04/10 xmega d 20.2 overview ........................................................................................................224 20.3 input sources .................................................................................................225 20.4 voltage reference selection ...........................................................................229 20.5 conversion result .........................................................................................229 20.6 compare function ..........................................................................................231 20.7 starting a conversion .....................................................................................231 20.8 adc clock and conversion timing ...............................................................231 20.9 adc input model ...........................................................................................233 20.10 interrupts and events .....................................................................................234 20.11 calibration .....................................................................................................234 20.12 register description - adc ...........................................................................234 20.13 register description - adc channel .............................................................241 20.14 register summary - adc ..............................................................................247 20.15 register summary - adc channel ................................................................248 20.16 interrupt vector summary .............................................................................248 21 ac - analog comparator .... .............. ............... .............. .............. ........ 249 21.1 features ........................................................................................................249 21.2 overview ........................................................................................................249 21.3 input channels ..............................................................................................251 21.4 start of signal compare ................................................................................251 21.5 generating interrupts and events ..................................................................251 21.6 window mode ................................................................................................251 21.7 input hysteresis .............................................................................................252 21.8 power consumption vs. propagation delay ....................................................252 21.9 register description ......................................................................................252 21.10 register summary .........................................................................................257 21.11 interrupt vector summary ..............................................................................257 22 program and debug interface ................. ................. ................ ........... 258 22.1 features ........................................................................................................258 22.2 overview ........................................................................................................258 22.3 pdi physical ..................................................................................................259 22.4 pdi controller ................................................................................................263 22.5 register description - pdi instruction and addressing registers .................267 22.6 register description - pdi control and status register ................................269 22.7 register summary .........................................................................................271
viii 8210b?avr?04/10 xmega d 23 memory programming ........ .............. ............... .............. .............. ........ 272 23.1 features ........................................................................................................272 23.2 overview ........................................................................................................272 23.3 nvm controller ..............................................................................................273 23.4 nvm commands ...........................................................................................273 23.5 nvm controller busy .....................................................................................273 23.6 flash and eeprom page buffers ........ ................ ................ ................ ........274 23.7 flash and eeprom programming sequen ces ............ ............ ............. ........275 23.8 protection of nvm .........................................................................................276 23.9 preventing nvm corruption ...........................................................................276 23.10 self-programming and boot loader support ................................................276 23.11 external programming ...................................................................................288 23.12 register description ......................................................................................294 23.13 register summary .........................................................................................294 24 peripheral module a ddress map ............ ................. ................ ........... 295 25 instruction set summary ... .............. ............... .............. .............. ........ 296 26 datasheet revision history .. ................ ................. ................ ............. 300 26.1 8210b ?04/10 ................................................................................................300 26.2 8210a ? 08/09 ...............................................................................................300 table of contents.......... ................. ................ ................. ................ ........... i
8210b?avr?04/10 ? 2010 atmel corporation. all rights reserved. atmel ? , atmel logo and combinations thereof, avr ? , avr ? logo and others are registered trade- marks, xmega tm and others are trademarks of atmel corporation or its s ubsidiaries. other terms and product names may be trademarks of others. headquarters international atmel corporation 2325 orchard parkway san jose, ca 95131 usa tel: 1(408) 441-0311 fax: 1(408) 487-2600 atmel asia unit 1-5 & 16, 19/f bea tower, millennium city 5 418 kwun tong road kwun tong, kowloon hong kong tel: (852) 2245-6100 fax: (852) 2722-1369 atmel europe le krebs 8, rue jean-pierre timbaud bp 309 78054 saint-quentin-en- yvelines cedex france tel: (33) 1-30-60-70-00 fax: (33) 1-30-60-71-11 atmel japan 9f, tonetsu shinkawa bldg. 1-24-8 shinkawa chuo-ku, tokyo 104-0033 japan tel: (81) 3-3523-3551 fax: (81) 3-3523-7581 product contact web site www.atmel.com technical support avr@atmel.com sales contact www.atmel.com/contacts literature requests www.atmel.com/literature disclaimer: the information in this document is provided in connection with atmel products. no license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of atmel products. except as set forth in atmel?s terms and condi- tions of sale located on atmel?s web site, atmel assumes no li ability whatsoever and disclaims any express, implied or statutor y warranty relating to its products including, but not limited to, the implied warranty of merchantability, fitness for a particu lar purpose, or non-infringement. in no event shall atmel be liable for any direct, indirect, consequential, punitive, special or i nciden- tal damages (including, without limitation, damages for loss of profits, business interruption, or loss of information) arising out of the use or inability to use this document, even if atme l has been advised of the possibility of such damages. atmel makes no representations or warranties with respect to the accuracy or comp leteness of the contents of this document and reserves the rig ht to make changes to specifications and product descriptions at any time without notice. atmel does not make any commitment to update the information contained her ein. unless specifically provided otherwise, atmel products are not suitable for, and shall not be used in, automotive applications. atmel?s products are not int ended, authorized, or warranted for use as components in applications in tended to support or sustain life.


▲Up To Search▲   

 
Price & Availability of XMEGAD

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X